From 3d53587901105ee6a4330d9fe8081adbe5e46f55 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Wed, 17 May 2023 15:34:31 +0200 Subject: [InstCombine] Don't create bitcast when simplifying round-trip The bitcast was not being added to the worklist. I could switch this to use the IRBuilder instead, but this bitcast is not relevant with opaque pointers anyway, so just drop it entirely. --- llvm/lib/Transforms/InstCombine/InstructionCombining.cpp | 8 +++----- llvm/test/Transforms/InstCombine/ptr-int-ptr-icmp.ll | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp index 5adbb8f66ee8..41cbcb11c1db 100644 --- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -361,7 +361,7 @@ static bool simplifyAssocCastAssoc(BinaryOperator *BinOp1, return true; } -// Simplifies IntToPtr/PtrToInt RoundTrip Cast To BitCast. +// Simplifies IntToPtr/PtrToInt RoundTrip Cast. // inttoptr ( ptrtoint (x) ) --> x Value *InstCombinerImpl::simplifyIntToPtrRoundTripCast(Value *Val) { auto *IntToPtr = dyn_cast(Val); @@ -373,10 +373,8 @@ Value *InstCombinerImpl::simplifyIntToPtrRoundTripCast(Value *Val) { CastTy->getPointerAddressSpace() == PtrToInt->getSrcTy()->getPointerAddressSpace() && DL.getTypeSizeInBits(PtrToInt->getSrcTy()) == - DL.getTypeSizeInBits(PtrToInt->getDestTy())) { - return CastInst::CreateBitOrPointerCast(PtrToInt->getOperand(0), CastTy, - "", PtrToInt); - } + DL.getTypeSizeInBits(PtrToInt->getDestTy())) + return PtrToInt->getOperand(0); } return nullptr; } diff --git a/llvm/test/Transforms/InstCombine/ptr-int-ptr-icmp.ll b/llvm/test/Transforms/InstCombine/ptr-int-ptr-icmp.ll index 5249aa4269e8..f23caaed9bcb 100644 --- a/llvm/test/Transforms/InstCombine/ptr-int-ptr-icmp.ll +++ b/llvm/test/Transforms/InstCombine/ptr-int-ptr-icmp.ll @@ -1,5 +1,5 @@ ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py -; RUN: opt -passes=instcombine -S -disable-i2p-p2i-opt < %s | FileCheck %s +; RUN: opt -passes=instcombine -instcombine-infinite-loop-threshold=2 -S -disable-i2p-p2i-opt < %s | FileCheck %s target datalayout = "e-p:64:64-p1:16:16-p2:32:32:32-p3:64:64:64" target triple = "x86_64-unknown-linux-gnu" -- cgit v1.2.1