[PATCH] D66608: [InstCombine] icmp eq/ne (gep inbounds P, Idx..), null -> icmp eq/ne P, null

Johannes Doerfert via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 22 13:14:57 PDT 2019


jdoerfert added inline comments.


================
Comment at: lib/Transforms/InstCombine/InstCombineCompares.cpp:882
   if (!isa<GetElementPtrInst>(RHS))
     RHS = RHS->stripPointerCasts();
 
----------------
Side note: This should probably be `RHS->stripPointerCastsSameRepresentation()` as we below argue about `nullness` of values and address spaces.


================
Comment at: lib/Transforms/InstCombine/InstCombineCompares.cpp:915
+    //   sources of full UB), so in this case, we just select between the two
+    //   non-poison cases (1 and 4 above).
+    return new ICmpInst(Cond, GEPLHS->getPointerOperand(), RHS);
----------------
I drew up the following table to convince myself this is valid given the restrictions checked in the conditional above: inbounds, rhs = zero, null is not valid.

| `b`ase/offset | zero     | not zero
| zero          | `b` = zero | poison
| not zero       | `b`     | not zero or poison




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

https://reviews.llvm.org/D66608





More information about the llvm-commits mailing list