[llvm] [InstCombine] Add combines for unsigned comparison of absolute value to constant (PR #176148)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 19 10:20:54 PST 2026
================
@@ -4301,6 +4301,42 @@ Instruction *InstCombinerImpl::foldICmpIntrinsicWithConstant(ICmpInst &Cmp,
II->getArgOperand(1));
}
break;
+ case Intrinsic::abs: {
+ if (!Cmp.getOperand(0)->hasOneUse())
+ return nullptr;
+
+ Value *X = II->getArgOperand(0);
+ bool IntMinIsPoison =
+ dyn_cast<ConstantInt>(II->getArgOperand(1))->getValue().isOne();
+
+ // abs(X) u> C --> C >= 0 ? `X + C u> 2 * C` : `false`
+ if (Pred == CmpInst::ICMP_UGT) {
+ if (C.isNegative()) {
+ Cmp.replaceAllUsesWith(ConstantInt::getFalse(Cmp.getType()));
+ return nullptr;
+ }
----------------
dtcxzyw wrote:
As we have simplified this case in other places, we can just bail out on this case.
```suggestion
if (Pred == CmpInst::ICMP_UGT && C.isNonNegative()) {
```
https://github.com/llvm/llvm-project/pull/176148
More information about the llvm-commits
mailing list