Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit b53f724

Browse files
committed
Update enforceKnownAlignment after the isWeakForLinker semantic change
Previously we would refrain from attempting to increase the linkage of available_externally globals because they were considered weak for the linker. Now they are treated more like a declaration instead of a weak definition. This was causing SSE alignment faults in Chromuim, when some code assumed it could increase the alignment of a dllimported global that it didn't control. http://crbug.com/509256 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@242091 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent c249168 commit b53f724

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

lib/Transforms/Utils/Local.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -900,13 +900,10 @@ static unsigned enforceKnownAlignment(Value *V, unsigned Align,
900900

901901
if (auto *GO = dyn_cast<GlobalObject>(V)) {
902902
// If there is a large requested alignment and we can, bump up the alignment
903-
// of the global.
904-
if (GO->isDeclaration())
905-
return Align;
906-
// If the memory we set aside for the global may not be the memory used by
907-
// the final program then it is impossible for us to reliably enforce the
908-
// preferred alignment.
909-
if (GO->isWeakForLinker())
903+
// of the global. If the memory we set aside for the global may not be the
904+
// memory used by the final program then it is impossible for us to reliably
905+
// enforce the preferred alignment.
906+
if (!GO->isStrongDefinitionForLinker())
910907
return Align;
911908

912909
if (GO->getAlignment() >= PrefAlign)

test/Transforms/InstCombine/align-external.ll

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@
33
; Don't assume that external global variables or those with weak linkage have
44
; their preferred alignment. They may only have the ABI minimum alignment.
55

6-
; CHECK: %s = shl i64 %a, 3
7-
; CHECK: %r = or i64 %s, ptrtoint (i32* @A to i64)
8-
; CHECK: %q = add i64 %r, 1
9-
; CHECK: ret i64 %q
10-
116
target datalayout = "i32:8:32"
127

138
@A = external global i32
149
@B = weak_odr global i32 0
1510

11+
@C = available_externally global <4 x i32> zeroinitializer, align 4
12+
; CHECK: @C = available_externally global <4 x i32> zeroinitializer, align 4
13+
1614
define i64 @foo(i64 %a) {
1715
%t = ptrtoint i32* @A to i64
1816
%s = shl i64 %a, 3
@@ -21,9 +19,23 @@ define i64 @foo(i64 %a) {
2119
ret i64 %q
2220
}
2321

22+
; CHECK-LABEL: define i64 @foo(i64 %a)
23+
; CHECK: %s = shl i64 %a, 3
24+
; CHECK: %r = or i64 %s, ptrtoint (i32* @A to i64)
25+
; CHECK: %q = add i64 %r, 1
26+
; CHECK: ret i64 %q
27+
2428
define i32 @bar() {
25-
; CHECK-LABEL: @bar(
2629
%r = load i32, i32* @B, align 1
27-
; CHECK: align 1
2830
ret i32 %r
2931
}
32+
33+
; CHECK-LABEL: @bar()
34+
; CHECK: align 1
35+
36+
define void @vec_store() {
37+
store <4 x i32> <i32 0, i32 1, i32 2, i32 3>, <4 x i32>* @C, align 4
38+
ret void
39+
}
40+
; CHECK: define void @vec_store()
41+
; CHECK: store <4 x i32> <i32 0, i32 1, i32 2, i32 3>, <4 x i32>* @C, align 4

0 commit comments

Comments
 (0)