[PATCH] D140798: [InstCombine] Fold zero check followed by decrement to usub.sat
Nikita Popov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 2 07:48:12 PST 2023
nikic added inline comments.
================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp:815
+ if (match(FalseVal, m_Zero())) {
+ if (Pred == ICmpInst::ICMP_NE) {
+ Pred = ICmpInst::getSwappedPredicate(Pred);
----------------
This is not going to trigger, because everything here is inside `Pred == ICmpInst::ICMP_EQ`. You'd want to check for isEquality() first (which accepts eq and ne), then have a check for ne where you invert the predicate and swap true/false, and then do the check for zero on the true value.
I'd suggest adding this test case to make sure the ne pattern is matched:
```
define i8 @test(i8 %a) {
%i = icmp ne i8 %a, 0
call void @use.i1(i1 %i)
%i1 = add i8 %a, -1
%i2 = select i1 %i, i8 %i1, i8 0
ret i8 %i2
}
declare void @use.i1(i1)
```
================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp:825
+ const APInt *Added;
+ if (match(FalseVal, m_Add(m_Specific(A), m_Negative(Added)))) {
+ APInt Sub = -*Added;
----------------
You can match `-1` using `m_AllOnes()`.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D140798/new/
https://reviews.llvm.org/D140798
More information about the llvm-commits
mailing list