[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 09:19:19 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.
----------------
bipmis wrote:

I am sure there are other cases we can benefit particularly where the Object Size is known and can be determined.
The idea here was also for situations where we do not know much about the object and cannot possibly identify a ptr as an Object. Also for many applications we do not exceed the 32bit allocation requirement. In these cases a compiler flag would benefit. 

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


More information about the llvm-commits mailing list