[PATCH] D140733: [InstSimplify] fold exact divide to poison if it is known to not divide evenly

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 28 12:49:50 PST 2022


lebedev.ri added a comment.

Do we do this for right-shifts already?
If not, might be easier to start with that.



================
Comment at: llvm/lib/Analysis/InstructionSimplify.cpp:1160
+    KnownBits KnownOp0 = computeKnownBits(Op0, Q.DL, 0, Q.AC, Q.CxtI, Q.DT);
+    if (KnownOp0.countMaxTrailingZeros() < DivC->countTrailingZeros())
+      return PoisonValue::get(Op0->getType());
----------------
I think this is a better proof:
```
https://alive2.llvm.org/ce/z/zCjKM7
But not: https://alive2.llvm.org/ce/z/-tz_RK
```


================
Comment at: llvm/lib/Analysis/InstructionSimplify.cpp:5692-5693
   case Instruction::SDiv:
-    return simplifySDivInst(LHS, RHS, Q, MaxRecurse);
+    return simplifySDivInst(LHS, RHS, false, Q, MaxRecurse);
   case Instruction::UDiv:
+    return simplifyUDivInst(LHS, RHS, false, Q, MaxRecurse);
----------------
/*IsExact=*/


================
Comment at: llvm/test/Transforms/InstSimplify/div.ll:380-381
   %o = or <2 x i8> %x, <i8 3, i8 3>
   %r = udiv exact <2 x i8> %o, <i8 12, i8 12>  ; can't divide exactly
   ret <2 x i8> %r
 }
----------------
Is there a non-uniform test? 
https://alive2.llvm.org/ce/z/Qkz5ac


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140733/new/

https://reviews.llvm.org/D140733



More information about the llvm-commits mailing list