[llvm] [ValueTracking] isNonZero trunc of sub of ptr2int's with recursive GEP where pointers are limited to a 32bit alloc. (PR #84933)

via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 12 08:47:20 PDT 2024


================
@@ -2539,7 +2544,80 @@ static bool isKnownNonZeroFromOperator(const Operator *I,
   case Instruction::ZExt:
     // ext X != 0 if X != 0.
     return isKnownNonZero(I->getOperand(0), Depth, Q);
+  case Instruction::Trunc:
+    // trunc(operand) is KnownNonZero if lower order bits of operand is a
+    // KnownNonZero. Handle scenarios like trunc i64 (sub(ptr2int, ptr2int)) to
+    // i32 / trunc i64 (lshr(sub(ptr2int, ptr2int))) to i32, where the ptrs are
+    // from same object and one of the pointers is a recursive GEP. And either
+    // the objectSize is known OR is indicative via a compiler flag, which
+    // suggests objectSize<4G.
----------------
goldsteinn wrote:

I wonder if we could instead support the `exact` flag in trunc to indicate that it doesn't change the high bits.
I don't think this is the only case where we wish we could peek past `trunc`.

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


More information about the llvm-commits mailing list