[llvm] c5a4d80 - [ValueTracking][MemCpyOpt] avoid crash on inttoptr with vector pointer type (PR48075)

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Sun Nov 22 09:55:20 PST 2020


Author: Sanjay Patel
Date: 2020-11-22T12:54:18-05:00
New Revision: c5a4d80fd47cfdae1995df46d0c407f78d8666e8

URL: https://github.com/llvm/llvm-project/commit/c5a4d80fd47cfdae1995df46d0c407f78d8666e8
DIFF: https://github.com/llvm/llvm-project/commit/c5a4d80fd47cfdae1995df46d0c407f78d8666e8.diff

LOG: [ValueTracking][MemCpyOpt] avoid crash on inttoptr with vector pointer type (PR48075)

Added: 
    

Modified: 
    llvm/lib/Analysis/ValueTracking.cpp
    llvm/test/Transforms/MemCpyOpt/crash.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index bcf35111502e..90f8dff87472 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -3610,12 +3610,13 @@ Value *llvm::isBytewiseValue(Value *V, const DataLayout &DL) {
 
   if (auto *CE = dyn_cast<ConstantExpr>(C)) {
     if (CE->getOpcode() == Instruction::IntToPtr) {
-      auto PS = DL.getPointerSizeInBits(
-          cast<PointerType>(CE->getType())->getAddressSpace());
-      return isBytewiseValue(
-          ConstantExpr::getIntegerCast(CE->getOperand(0),
-                                       Type::getIntNTy(Ctx, PS), false),
-          DL);
+      if (auto *PtrTy = dyn_cast<PointerType>(CE->getType())) {
+        unsigned BitWidth = DL.getPointerSizeInBits(PtrTy->getAddressSpace());
+        return isBytewiseValue(
+            ConstantExpr::getIntegerCast(CE->getOperand(0),
+                                         Type::getIntNTy(Ctx, BitWidth), false),
+            DL);
+      }
     }
   }
 

diff  --git a/llvm/test/Transforms/MemCpyOpt/crash.ll b/llvm/test/Transforms/MemCpyOpt/crash.ll
index f70f10429f84..73635891c683 100644
--- a/llvm/test/Transforms/MemCpyOpt/crash.ll
+++ b/llvm/test/Transforms/MemCpyOpt/crash.ll
@@ -83,3 +83,16 @@ define void @test2(i32 %cmd) nounwind {
   call void @llvm.memcpy.p0i8.p0i8.i64(i8* null, i8* undef, i64 20, i1 false) nounwind
   ret void
 }
+
+; https://llvm.org/PR48075
+
+ at g = external global i16, align 1
+
+define void @inttoptr_constexpr_crash(<1 x i16*>* %p) {
+; CHECK-LABEL: @inttoptr_constexpr_crash(
+; CHECK-NEXT:    store <1 x i16*> inttoptr (<1 x i16> bitcast (<2 x i8> <i8 ptrtoint (i16* @g to i8), i8 ptrtoint (i16* @g to i8)> to <1 x i16>) to <1 x i16*>), <1 x i16*>* [[P:%.*]], align 1
+; CHECK-NEXT:    ret void
+;
+  store <1 x i16*> inttoptr (<1 x i16> bitcast (<2 x i8> <i8 ptrtoint (i16* @g to i8), i8 ptrtoint (i16* @g to i8)> to <1 x i16>) to <1 x i16*>), <1 x i16*>* %p, align 1
+  ret void
+}


        


More information about the llvm-commits mailing list