[llvm] 1ab37fa - [InstCombine] Fix worklist management when simplifying demanded bits

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 18 08:57:13 PST 2020


Author: Nikita Popov
Date: 2020-02-18T17:55:40+01:00
New Revision: 1ab37fad61ab3b44bdb11b6865925321fccb7947

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

LOG: [InstCombine] Fix worklist management when simplifying demanded bits

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
index bf91d99edf24..25a73c83d8b5 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
@@ -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;
 }
 

diff  --git a/llvm/test/Transforms/InstCombine/pr44541.ll b/llvm/test/Transforms/InstCombine/pr44541.ll
index 782526a10e33..3d4082a77091 100644
--- a/llvm/test/Transforms/InstCombine/pr44541.ll
+++ b/llvm/test/Transforms/InstCombine/pr44541.ll
@@ -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.
 

diff  --git a/llvm/test/Transforms/InstCombine/select-imm-canon.ll b/llvm/test/Transforms/InstCombine/select-imm-canon.ll
index f73c32bf2380..4c59be668626 100644
--- a/llvm/test/Transforms/InstCombine/select-imm-canon.ll
+++ b/llvm/test/Transforms/InstCombine/select-imm-canon.ll
@@ -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(


        


More information about the llvm-commits mailing list