[PATCH] D99481: [InstCombine] Fix miscompile on GEP+load to icmp fold (PR45210)

Hyeongyu Kim via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 28 17:15:38 PDT 2021


hyeongyukim updated this revision to Diff 348602.

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

https://reviews.llvm.org/D99481

Files:
  llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp


Index: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -279,8 +279,7 @@
       Idx = Builder.CreateTrunc(Idx, IntPtrTy);
 
     unsigned ElementSize =
-    DL.getTypeAllocSize(Init->getType()->getArrayElementType());
-
+        DL.getTypeAllocSize(Init->getType()->getArrayElementType());
 
     // If inbounds keyword is not present, Idx * ElementSize can overflow.
     // Let's assume that ElementSize is 2 and the wanted value is at offset 0.
@@ -290,7 +289,7 @@
     // comparison is false if Idx was 0x80..00.
     // We need to erase the highest countTrailingZeros(ElementSize) bits of Idx.
     if (countTrailingZeros(ElementSize) != 0) {
-      Value *Mask = ConstantInt::get(Idx->getType(), -1);
+      Value *Mask = ConstantInt::getSigned(Idx->getType(), -1);
       Mask = Builder.CreateLShr(Mask, countTrailingZeros(ElementSize));
       Idx = Builder.CreateAnd(Idx, Mask);
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99481.348602.patch
Type: text/x-patch
Size: 1093 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210529/bc38cc5f/attachment.bin>


More information about the llvm-commits mailing list