[InstCombine] Improve simplify demanded bits worklist management
authorNikita Popov <nikita.ppv@gmail.com>
Thu, 20 Feb 2020 21:19:10 +0000 (22:19 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Fri, 21 Feb 2020 17:51:41 +0000 (18:51 +0100)
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.

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

index 25a73c8..a017abf 100644 (file)
@@ -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;
 }
 
index 7f28260..ed32bb1 100644 (file)
@@ -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) {