[PATCH] D19390: folding compares for distinct allocations

Anna Thomas via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 22 09:32:39 PDT 2016


anna 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))
----------------
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. 





http://reviews.llvm.org/D19390





More information about the llvm-commits mailing list