[InstCombine] Fix worklist management when simplifying demanded bits
authorNikita Popov <nikita.ppv@gmail.com>
Sat, 11 Jan 2020 15:58:01 +0000 (16:58 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Tue, 18 Feb 2020 16:55:40 +0000 (17:55 +0100)
When simplifying demanded bits, we currently only report the
instruction on which SimplifyDemandedBits was called as changed.
However, this is a recursive call, and the actually modified
instruction will usually be further up the chain. Additionally,
all the intermediate instructions should also be revisited,
as additional combines may be possible after the demanded bits
simplification. We fix this by explicitly adding them back to the
worklist.

Differential Revision: https://reviews.llvm.org/D72944

llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
llvm/test/Transforms/InstCombine/pr44541.ll
llvm/test/Transforms/InstCombine/select-imm-canon.ll

index bf91d99edf24c61ed314b616ec9c12c97d23625e..25a73c83d8b53d10050f829a5ca82d75ce2dbf10 100644 (file)
@@ -88,6 +88,8 @@ bool InstCombiner::SimplifyDemandedBits(Instruction *I, unsigned OpNo,
                                           Depth, I);
   if (!NewVal) return false;
   U = NewVal;
+  // Add the simplified instruction back to the worklist.
+  Worklist.addValue(U.get());
   return true;
 }
 
index 782526a10e33ac8c8694c0bbfa6ac85c71422278..3d4082a770911e56207a822101b7bc8986e70601 100644 (file)
@@ -1,5 +1,5 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
-; RUN: opt -S -instcombine -expensive-combines=0 -instcombine-infinite-loop-threshold=3 < %s | FileCheck %s
+; RUN: opt -S -instcombine -expensive-combines=0 -instcombine-infinite-loop-threshold=2 < %s | FileCheck %s
 
 ; This test used to cause an infinite combine loop.
 
index f73c32bf23809bae56de59fee342577d37602ac3..4c59be6686261f68d9c0eb76f33d949925e961c6 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=3 -S | FileCheck %s
 
 define i8 @single(i32 %A) {
 ; CHECK-LABEL: @single(