Skip to content

Commit 3f0b779

Browse files
committed
Merging r169719: into 3.2 release branch.
Fix PR14548: SROA was crashing on a mixture of i1 and i8 loads and stores. When SROA was evaluating a mixture of i1 and i8 loads and stores, in just a particular case, it would tickle a latent bug where we compared bits to bytes rather than bits to bits. As a consequence of the latent bug, we would allow integers through which were not byte-size multiples, a situation the later rewriting code was never intended to handle. In release builds this could trigger all manner of oddities, but the reported issue in PR14548 was forming invalid bitcast instructions. The only downside of this fix is that it makes it more clear that SROA in its current form is not capable of handling mixed i1 and i8 loads and stores. Sometimes with the previous code this would work by luck, but usually it would crash, so I'm not terribly worried. I'll watch the LNT numbers just to be sure. git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_32@169735 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 710e1c5 commit 3f0b779

File tree

3 files changed

+33
-9
lines changed

3 files changed

+33
-9
lines changed

lib/Transforms/Scalar/SROA.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2201,7 +2201,7 @@ static bool isIntegerWideningViable(const DataLayout &TD,
22012201
if (RelBegin == 0 && RelEnd == Size)
22022202
WholeAllocaOp = true;
22032203
if (IntegerType *ITy = dyn_cast<IntegerType>(LI->getType())) {
2204-
if (ITy->getBitWidth() < TD.getTypeStoreSize(ITy))
2204+
if (ITy->getBitWidth() < TD.getTypeStoreSizeInBits(ITy))
22052205
return false;
22062206
continue;
22072207
}
@@ -2217,7 +2217,7 @@ static bool isIntegerWideningViable(const DataLayout &TD,
22172217
if (RelBegin == 0 && RelEnd == Size)
22182218
WholeAllocaOp = true;
22192219
if (IntegerType *ITy = dyn_cast<IntegerType>(ValueTy)) {
2220-
if (ITy->getBitWidth() < TD.getTypeStoreSize(ITy))
2220+
if (ITy->getBitWidth() < TD.getTypeStoreSizeInBits(ITy))
22212221
return false;
22222222
continue;
22232223
}

test/Transforms/SROA/basictest.ll

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,3 +1147,32 @@ define void @PR14465() {
11471147
ret void
11481148
; CHECK: ret
11491149
}
1150+
1151+
define void @PR14548(i1 %x) {
1152+
; Handle a mixture of i1 and i8 loads and stores to allocas. This particular
1153+
; pattern caused crashes and invalid output in the PR, and its nature will
1154+
; trigger a mixture in several permutations as we resolve each alloca
1155+
; iteratively.
1156+
; Note that we don't do a particularly good *job* of handling these mixtures,
1157+
; but the hope is that this is very rare.
1158+
; CHECK: @PR14548
1159+
1160+
entry:
1161+
%a = alloca <{ i1 }>, align 8
1162+
%b = alloca <{ i1 }>, align 8
1163+
; Nothing of interest is simplified here.
1164+
; CHECK: alloca
1165+
; CHECK: alloca
1166+
1167+
%b.i1 = bitcast <{ i1 }>* %b to i1*
1168+
store i1 %x, i1* %b.i1, align 8
1169+
%b.i8 = bitcast <{ i1 }>* %b to i8*
1170+
%foo = load i8* %b.i8, align 1
1171+
1172+
%a.i8 = bitcast <{ i1 }>* %a to i8*
1173+
call void @llvm.memcpy.p0i8.p0i8.i32(i8* %a.i8, i8* %b.i8, i32 1, i32 1, i1 false) nounwind
1174+
%bar = load i8* %a.i8, align 1
1175+
%a.i1 = getelementptr inbounds <{ i1 }>* %a, i32 0, i32 0
1176+
%baz = load i1* %a.i1, align 1
1177+
ret void
1178+
}

test/Transforms/SROA/big-endian.ll

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,9 @@ entry:
8282

8383
%a0i16ptr = bitcast i8* %a0ptr to i16*
8484
store i16 1, i16* %a0i16ptr
85-
; CHECK: %[[mask0:.*]] = and i16 1, -16
86-
87-
%a1i4ptr = bitcast i8* %a1ptr to i4*
88-
store i4 1, i4* %a1i4ptr
89-
; CHECK-NEXT: %[[insert0:.*]] = or i16 %[[mask0]], 1
9085

9186
store i8 1, i8* %a2ptr
92-
; CHECK-NEXT: %[[mask1:.*]] = and i40 undef, 4294967295
87+
; CHECK: %[[mask1:.*]] = and i40 undef, 4294967295
9388
; CHECK-NEXT: %[[insert1:.*]] = or i40 %[[mask1]], 4294967296
9489

9590
%a3i24ptr = bitcast i8* %a3ptr to i24*
@@ -110,7 +105,7 @@ entry:
110105
%ai = load i56* %aiptr
111106
%ret = zext i56 %ai to i64
112107
ret i64 %ret
113-
; CHECK-NEXT: %[[ext4:.*]] = zext i16 %[[insert0]] to i56
108+
; CHECK-NEXT: %[[ext4:.*]] = zext i16 1 to i56
114109
; CHECK-NEXT: %[[shift4:.*]] = shl i56 %[[ext4]], 40
115110
; CHECK-NEXT: %[[mask4:.*]] = and i56 %[[insert3]], 1099511627775
116111
; CHECK-NEXT: %[[insert4:.*]] = or i56 %[[mask4]], %[[shift4]]

0 commit comments

Comments
 (0)