We can simplify
icmp <pred> phi(C1, C2, ...), C
with
phi(icmp(C1, C), icmp(C2, C), ...)
provided that all comparison of constants are constants themselves.
Paths
| Differential D81151
[InstCombine] Simplify compare of Phi with constant inputs against a constant ClosedPublic Authored by mkazantsev on Jun 4 2020, 5:31 AM.
Details Summary We can simplify icmp <pred> phi(C1, C2, ...), C with phi(icmp(C1, C), icmp(C2, C), ...) provided that all comparison of constants are constants themselves.
Diff Detail
Event Timelinelebedev.ri added inline comments.
mkazantsev added inline comments.
mkazantsev added inline comments.
Comment Actions Addressed comments:
This revision is now accepted and ready to land.Jun 5 2020, 12:28 AM Closed by commit rG16b7eb6dd124: [InstCombine] Simplify compare of Phi with constant inputs against a constant (authored by mkazantsev). · Explain WhyJun 5 2020, 3:17 AM This revision was automatically updated to reflect the committed changes. Comment Actions This breaks tests check-clang: http://45.33.8.238/linux/19487/step_7.txt Please take a look and revert for now if it takes a while to fix. Comment Actions
And as is tradition, an overstepping end-to-end test.. Comment Actions This looks like its responsible for the exceptions.m test failures on some bots: http://lab.llvm.org:8011/builders/llvm-avr-linux/builds/2189 /home/buildbot-worker/llvm-avr-linux/llvm-avr-linux/llvm/clang/test/CodeGenObjC/exceptions.m:100:12: error: CHECK: expected string not found in input // CHECK: [[DEST1:%.*]] = phi i32 [ 0, {{%.*}} ], [ 3, {{%.*}} ] ^ <stdin>:195:37: note: scanning from here call void @objc_exception_try_exit(%struct._objc_exception_data* nonnull %exceptiondata.ptr) #5 ^ <stdin>:219:2: note: possible intended match here %1 = load i32, i32* %x, align 4, !tbaa !7 ^ Comment Actions It looks like this may introduce a dead-code elimination regression with -Oz: https://github.com/llvm/llvm-project/issues/53318
Revision Contents
Diff 268728 llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/test/Transforms/InstCombine/icmp-constant-phi.ll
llvm/test/Transforms/InstCombine/indexed-gep-compares.ll
llvm/test/Transforms/InstCombine/zext-or-icmp.ll
|
I don't think you need one-use check - you produce a single instruction,
and root icmp from which you started matching always goes away (is replaced by new phi)