Fix PR10104 by adding a bounds check on a vector element access check. It was
authorCameron Zwarich <zwarich@apple.com>
Thu, 9 Jun 2011 01:45:33 +0000 (01:45 +0000)
committerCameron Zwarich <zwarich@apple.com>
Thu, 9 Jun 2011 01:45:33 +0000 (01:45 +0000)
assuming that all offsets are legal vector accesses, and thus trying to access
the float member of { <2 x float>, float } as the 3rd element of the first
member.

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

lib/Transforms/Scalar/ScalarReplAggregates.cpp
test/Transforms/ScalarRepl/2011-06-08-VectorExtractValue.ll

index 9f286b564227bf2933e0c98184038f172d458115..09e597fe666250bd5ea926ed1291a1c2319bd1da 100644 (file)
@@ -342,7 +342,10 @@ void ConvertToScalarInfo::MergeInType(const Type *In, uint64_t Offset,
     // If we're accessing something that could be an element of a vector, see
     // if the implied vector agrees with what we already have and if Offset is
     // compatible with it.
-    if (Offset % EltSize == 0 && AllocaSize % EltSize == 0) {
+    if (Offset % EltSize == 0 && AllocaSize % EltSize == 0 &&
+        Offset * 8 <
+          (VectorTy ? VectorTy->getPrimitiveSizeInBits()
+                    : (AllocaSize / EltSize) * In->getPrimitiveSizeInBits())) {
       if (!VectorTy) {
         VectorTy = VectorType::get(In, AllocaSize/EltSize);
         return;
index 0b008f48dbe64210f20940536aa02856754b39a0..32e67fbce78b3446fc061551ce762ab62256dea1 100644 (file)
@@ -41,9 +41,11 @@ entry:
 
 ; CHECK: test2
 ; CHECK-NOT: alloca
-; CHECK: insertelement <2 x float> zeroinitializer
-; CHECK: extractelement <2 x float> %tmp2
-; CHECK: extractelement <2 x float> %tmp2
+; CHECK: and i128
+; CHECK: or i128
+; CHECK: trunc i128
+; CHECK-NOT: insertelement
+; CHECK-NOT: extractelement
 
 define float @test2() uwtable ssp {
 entry: