[llvm] e65f213 - [InstCombine] canonicalizeICmpPredicate(): use InstCombiner::replaceInstUsesWith() instead of RAUW

Roman Lebedev via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 29 05:11:21 PDT 2020


Author: Roman Lebedev
Date: 2020-08-29T15:10:14+03:00
New Revision: e65f2131782bc39ec66fc9c74991ff6c2ff1d93b

URL: https://github.com/llvm/llvm-project/commit/e65f2131782bc39ec66fc9c74991ff6c2ff1d93b
DIFF: https://github.com/llvm/llvm-project/commit/e65f2131782bc39ec66fc9c74991ff6c2ff1d93b.diff

LOG: [InstCombine] canonicalizeICmpPredicate(): use InstCombiner::replaceInstUsesWith() instead of RAUW

We really shouldn't use RAUW in InstCombine
because we should consistently update Worklist to avoid extra iterations.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index c6017b4fc577..ea955b3b3b0d 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -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 "

diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
index 86b0bfe24d28..a03cb5e47051 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
+++ b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
@@ -120,6 +120,7 @@ class LLVM_LIBRARY_VISIBILITY InstCombinerImpl final
   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);


        


More information about the llvm-commits mailing list