[InstCombine] canonicalizeICmpPredicate(): use InstCombiner::replaceInstUsesWith...
authorRoman Lebedev <lebedev.ri@gmail.com>
Sat, 29 Aug 2020 11:59:09 +0000 (14:59 +0300)
committerRoman Lebedev <lebedev.ri@gmail.com>
Sat, 29 Aug 2020 12:10:14 +0000 (15:10 +0300)
We really shouldn't use RAUW in InstCombine
because we should consistently update Worklist to avoid extra iterations.

llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/lib/Transforms/InstCombine/InstCombineInternal.h

index c6017b4..ea955b3 100644 (file)
@@ -5306,7 +5306,7 @@ static ICmpInst *canonicalizeCmpWithConstant(ICmpInst &I) {
 
 /// If we have a comparison with a non-canonical predicate, if we can update
 /// all the users, invert the predicate and adjust all the users.
-static CmpInst *canonicalizeICmpPredicate(CmpInst &I) {
+CmpInst *InstCombinerImpl::canonicalizeICmpPredicate(CmpInst &I) {
   // Is the predicate already canonical?
   CmpInst::Predicate Pred = I.getPredicate();
   if (InstCombiner::isCanonicalPredicate(Pred))
@@ -5334,7 +5334,7 @@ static CmpInst *canonicalizeICmpPredicate(CmpInst &I) {
       cast<BranchInst>(U)->swapSuccessors(); // swaps prof metadata too
       break;
     case Instruction::Xor:
-      U->replaceAllUsesWith(&I);
+      replaceInstUsesWith(cast<Instruction>(*U), &I);
       break;
     default:
       llvm_unreachable("Got unexpected user - out of sync with "
index 86b0bfe..a03cb5e 100644 (file)
@@ -120,6 +120,7 @@ public:
   Instruction *visitLShr(BinaryOperator &I);
   Instruction *commonShiftTransforms(BinaryOperator &I);
   Instruction *visitFCmpInst(FCmpInst &I);
+  CmpInst *canonicalizeICmpPredicate(CmpInst &I);
   Instruction *visitICmpInst(ICmpInst &I);
   Instruction *FoldShiftByConstant(Value *Op0, Constant *Op1,
                                    BinaryOperator &I);