[PATCH] D19390: folding compares for distinct allocations

David Majnemer via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 22 09:47:01 PDT 2016


majnemer added inline comments.

================
Comment at: lib/Transforms/InstCombine/InstructionCombining.cpp:1905-1909
@@ -1902,2 +1904,7 @@
         unsigned OtherIndex = (ICI->getOperand(0) == PI) ? 1 : 0;
-        if (!isNeverEqualToUnescapedAlloc(ICI->getOperand(OtherIndex)))
+        // We avoid the case of allocation being compared to itself.
+        // Strip off pointer and zero GEPs
+        if (PI ==
+                ICI->getOperand(OtherIndex)
+                    ->stripPointerCastsNoFollowAliases() ||
+            !isNeverEqualToUnescapedAlloc(ICI->getOperand(OtherIndex), TLI))
----------------
anna wrote:
> majnemer wrote:
> > I don't think this will do the right thing if `%x = allocation` is compared with `gep(gep(%x, 1), -1)`.
> Thats true!
> 
> I think this would handle all cases of GEP and bitcasts:
> `PI == ICI->getOperand(OtherIndex)->stripInBoundsOffsets()`
> Mainly, the GEP indices could be non-contant: `gep(gep(%x, y), z)` and still point to `%x`  if y and z are 1 and -1 respectively. 
> 
> 
> 
In that case, what if we have `gep(0, %x)` ?  I am not an expert on the GEP rules but someone else (@sanjoy?) might know.


http://reviews.llvm.org/D19390





More information about the llvm-commits mailing list