[llvm] b178555 - [InstCombine] Improve simplify demanded bits worklist management

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 21 09:51:50 PST 2020


Author: Nikita Popov
Date: 2020-02-21T18:51:41+01:00
New Revision: b178555318cdccecc9d3fb4af89b4a765cb0e48c

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

LOG: [InstCombine] Improve simplify demanded bits worklist management

This fixes a small mistake from D72944: The worklist add should
happen before assigning the new operand, not after.

In case an actual replacement happens, the old operand needs to
be added for DCE. If no actual replacement happens, then old/new
are the same, so it doesn't matter.

This drops one iteration from the annotated test case.

Added: 
    

Modified: 
    llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
    llvm/test/Transforms/InstCombine/2010-11-01-lshr-mask.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
index 25a73c83d8b5..a017abfe836c 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
@@ -87,9 +87,9 @@ bool InstCombiner::SimplifyDemandedBits(Instruction *I, unsigned OpNo,
   Value *NewVal = SimplifyDemandedUseBits(U.get(), DemandedMask, Known,
                                           Depth, I);
   if (!NewVal) return false;
-  U = NewVal;
-  // Add the simplified instruction back to the worklist.
+  // Add the old operand back to the worklist.
   Worklist.addValue(U.get());
+  U = NewVal;
   return true;
 }
 

diff  --git a/llvm/test/Transforms/InstCombine/2010-11-01-lshr-mask.ll b/llvm/test/Transforms/InstCombine/2010-11-01-lshr-mask.ll
index 7f2826071a96..ed32bb1aa9d5 100644
--- a/llvm/test/Transforms/InstCombine/2010-11-01-lshr-mask.ll
+++ b/llvm/test/Transforms/InstCombine/2010-11-01-lshr-mask.ll
@@ -1,4 +1,4 @@
-; RUN: opt -instcombine -S < %s | FileCheck %s
+; RUN: opt -instcombine -instcombine-infinite-loop-threshold=3 -S < %s | FileCheck %s
 
 ; <rdar://problem/8606771>
 define i32 @main(i32 %argc) {


        


More information about the llvm-commits mailing list