[InstCombine] Use IRBuilder to create bitcast
authorNikita Popov <nikita.ppv@gmail.com>
Fri, 28 Feb 2020 21:29:54 +0000 (22:29 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Wed, 4 Mar 2020 17:28:38 +0000 (18:28 +0100)
This makes sure that the constant expression bitcast goes through
target-dependent constant folding, and thus avoids an additional
iteration of InstCombine.

llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
llvm/test/Transforms/InstCombine/icmp-xor-signbit.ll

index fc4d438c42b20dd58cd63233c6a6fd9a07208564..52edda6af1ef9bda42b5884f50e764386eaac863 100644 (file)
@@ -2151,7 +2151,7 @@ static Instruction *foldBitCastBitwiseLogic(BitCastInst &BitCast,
   if (match(BO->getOperand(1), m_Constant(C))) {
     // bitcast (logic X, C) --> logic (bitcast X, C')
     Value *CastedOp0 = Builder.CreateBitCast(BO->getOperand(0), DestTy);
-    Value *CastedC = ConstantExpr::getBitCast(C, DestTy);
+    Value *CastedC = Builder.CreateBitCast(C, DestTy);
     return BinaryOperator::Create(BO->getOpcode(), CastedOp0, CastedC);
   }
 
index dab9b5e9fefe6ccdc0b424162c5227b78cec5909..ac5394351205c5248392a7519325f172ccb87e23 100644 (file)
@@ -1,5 +1,5 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
-; RUN: opt < %s -instcombine -S | FileCheck %s
+; RUN: opt < %s -instcombine -instcombine-infinite-loop-threshold=2 -S | FileCheck %s
 
 ; icmp u/s (a ^ signmask), (b ^ signmask) --> icmp s/u a, b