[Unroll] Do not crash trying to propagate a value to vector load.
authorMichael Zolotukhin <mzolotukhin@apple.com>
Tue, 22 Sep 2015 22:27:12 +0000 (22:27 +0000)
committerMichael Zolotukhin <mzolotukhin@apple.com>
Tue, 22 Sep 2015 22:27:12 +0000 (22:27 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@248333 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/LoopUnrollPass.cpp
test/Transforms/LoopUnroll/full-unroll-crashers.ll

index d9236a2c773b66b216418d93b282053506eed793..97c51dff84fb647ed40d4481722f9affb8ed52d5 100644 (file)
@@ -423,6 +423,12 @@ private:
     if (!CDS)
       return false;
 
+    // We might have a vector load from an array. FIXME: for now we just bail
+    // out in this case, but we should be able to resolve and simplify such
+    // loads.
+    if(!CDS->isElementTypeCompatible(I.getType()))
+      return false;
+
     int ElemSize = CDS->getElementType()->getPrimitiveSizeInBits() / 8U;
     assert(SimplifiedAddrOp->getValue().getActiveBits() < 64 &&
            "Unexpectedly large index value.");
index eebf5a0a2f2d531e7cd08e692c6714c27a181639..e932851042ad9c5d8010acc90a7251ee921f86f0 100644 (file)
@@ -81,3 +81,22 @@ for.inc:
 for.end:
   ret void
 }
+
+define <4 x i32> @vec_load() {
+entry:
+  br label %for.body
+
+for.body:
+  %phi = phi i64 [ 0, %entry ], [ %inc, %for.body ]
+  %vec_phi = phi <4 x i32> [ <i32 0, i32 0, i32 0, i32 0>, %entry ], [ %r, %for.body ]
+  %arrayidx = getelementptr inbounds [10 x i32], [10 x i32]* @known_constant, i64 0, i64 %phi
+  %bc = bitcast i32* %arrayidx to <4 x i32>*
+  %x = load <4 x i32>, < 4 x i32>* %bc, align 4
+  %r = add <4 x i32> %x, %vec_phi
+  %inc = add nuw nsw i64 %phi, 1
+  %cmp = icmp ult i64 %inc, 999
+  br i1 %cmp, label %for.body, label %for.exit
+
+for.exit:
+  ret <4 x i32> %r
+}