Fix another SROA crasher, PR14601.
authorChandler Carruth <chandlerc@gmail.com>
Mon, 17 Dec 2012 18:48:07 +0000 (18:48 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Mon, 17 Dec 2012 18:48:07 +0000 (18:48 +0000)
This was a silly oversight, we weren't pruning allocas which were used
by variable-length memory intrinsics from the set that could be widened
and promoted as integers. Fix that.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@170353 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/SROA.cpp
test/Transforms/SROA/basictest.ll

index ab61a2fd674d87e9205af23a48555ede951a3976..a0ee849a03f0dab035cc2879ad2ce3883d60bacc 100644 (file)
@@ -2150,7 +2150,7 @@ static bool isIntegerWideningViable(const DataLayout &TD,
           !canConvertValue(TD, ValueTy, AllocaTy))
         return false;
     } else if (MemIntrinsic *MI = dyn_cast<MemIntrinsic>(I->U->getUser())) {
-      if (MI->isVolatile())
+      if (MI->isVolatile() || !isa<Constant>(MI->getLength()))
         return false;
       if (MemTransferInst *MTI = dyn_cast<MemTransferInst>(I->U->getUser())) {
         const AllocaPartitioning::MemTransferOffsets &MTO
index 7856a7e4396843ea21bb1e972b17be41a1052574..efc01acd591195991033a324373e7c443daeac09 100644 (file)
@@ -1208,3 +1208,18 @@ entry:
   ret i32 %y
 ; CHECK: ret i32
 }
+
+define i32 @PR14601(i32 %x) {
+; Don't try to form a promotable integer alloca when there is a variable length
+; memory intrinsic.
+; CHECK: @PR14601
+
+entry:
+  %a = alloca i32
+; CHECK: alloca
+
+  %a.i8 = bitcast i32* %a to i8*
+  call void @llvm.memset.p0i8.i32(i8* %a.i8, i8 0, i32 %x, i32 1, i1 false)
+  %v = load i32* %a
+  ret i32 %v
+}