[llvm] [InstCombine] Simplify compare abs(X) and X. (PR #76385)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 29 04:41:23 PST 2023


================
@@ -7109,6 +7109,47 @@ Instruction *InstCombinerImpl::visitICmpInst(ICmpInst &I) {
     }
   }
 
+  {
+    Value *X;
+    Constant *C;
+    if (match(Op0, m_OneUse(m_Intrinsic<Intrinsic::abs>(m_Value(X),
----------------
dtcxzyw wrote:

Does it handle the commuted case `icmp pred X, abs(X)`? Is it guaranteed that the complexity-based canonicalization always places `X` in RHS?
Could you please add a test that commutes operands?
```
define i1 @icmp_sge_abs(i4 %arg) {
   %x = mul i4 %arg, %arg ; thwart complexity-based canonicalization
   %abs = call i4 @llvm.abs.i4(i4 %x, i1 true)
   %cmp = icmp sge i4 %x, %abs
   ret i1 %cmp
 }

```


https://github.com/llvm/llvm-project/pull/76385


More information about the llvm-commits mailing list