[PATCH] D154206: [InstCombine] Fold comparison of usub.sat
Nikita Popov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 30 07:16:28 PDT 2023
nikic added a comment.
Could you please add alive2 proofs for these transforms?
================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:3440
+ Pred == ICmpInst::ICMP_EQ ? ICmpInst::ICMP_UGE : ICmpInst::ICMP_ULT;
+ if (match(II1, m_Constant()))
+ return BinaryOperator::CreateAnd(
----------------
m_ImmConstant
================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:3672
+ Value *II0 = II->getOperand(0);
+ Value *II1 = II->getOperand(1);
+ if (match(II1, m_Constant())) {
----------------
Add comment explaining the transform, something like this:
```
// usub.sat(X, C) pred C2
// -> (X < C ? 0 : X - C) pred C2
// -> X >= C && (X - C) pred C2 (if 0 pred C2 is false)
// -> X < C || (X - C) pred C2 (if 0 pred C2 is true)
```
================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:3682
+ Builder.CreateICmp(Pred, Builder.CreateSub(II0, II1), Builder.getInt(C)));
+ }
+ break;
----------------
Some of these cases will end up producing 2 instructions (add + icmp), so I think we should add a one-use limitation on the intrinsic.
================
Comment at: llvm/test/Transforms/InstCombine/icmp-usub-sat.ll:120
+
+declare i8 @llvm.usub.sat.i8(i8, i8)
----------------
Add a multi-use and vector test.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D154206/new/
https://reviews.llvm.org/D154206
More information about the llvm-commits
mailing list