Skip to content

Commit a24cc48

Browse files
committed
[ArgPromotion] Add alignment test (NFC)
This shows a miscompile in the current argpromotion implementation: We may speculatively execute overaligned loads.
1 parent d2e5d35 commit a24cc48

File tree

1 file changed

+84
-0
lines changed
  • llvm/test/Transforms/ArgumentPromotion

1 file changed

+84
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --scrub-attributes
2+
; RUN: opt -S -argpromotion < %s | FileCheck %s
3+
4+
define internal i32 @callee_must_exec(i32* %p) {
5+
; CHECK-LABEL: define {{[^@]+}}@callee_must_exec
6+
; CHECK-SAME: (i32 [[P_VAL:%.*]]) {
7+
; CHECK-NEXT: ret i32 [[P_VAL]]
8+
;
9+
%x = load i32, i32* %p, align 16
10+
ret i32 %x
11+
}
12+
13+
define void @caller_must_exec(i32* %p) {
14+
; CHECK-LABEL: define {{[^@]+}}@caller_must_exec
15+
; CHECK-SAME: (i32* [[P:%.*]]) {
16+
; CHECK-NEXT: [[P_VAL:%.*]] = load i32, i32* [[P]], align 16
17+
; CHECK-NEXT: [[TMP1:%.*]] = call i32 @callee_must_exec(i32 [[P_VAL]])
18+
; CHECK-NEXT: ret void
19+
;
20+
call i32 @callee_must_exec(i32* %p)
21+
ret void
22+
}
23+
24+
define internal i32 @callee_guaranteed_aligned(i1 %c, i32* %p) {
25+
; CHECK-LABEL: define {{[^@]+}}@callee_guaranteed_aligned
26+
; CHECK-SAME: (i1 [[C:%.*]], i32 [[P_VAL:%.*]]) {
27+
; CHECK-NEXT: br i1 [[C]], label [[IF:%.*]], label [[ELSE:%.*]]
28+
; CHECK: if:
29+
; CHECK-NEXT: ret i32 [[P_VAL]]
30+
; CHECK: else:
31+
; CHECK-NEXT: ret i32 -1
32+
;
33+
br i1 %c, label %if, label %else
34+
35+
if:
36+
%x = load i32, i32* %p, align 16
37+
ret i32 %x
38+
39+
else:
40+
ret i32 -1
41+
}
42+
43+
define void @caller_guaranteed_aligned(i1 %c, i32* align 16 dereferenceable(4) %p) {
44+
; CHECK-LABEL: define {{[^@]+}}@caller_guaranteed_aligned
45+
; CHECK-SAME: (i1 [[C:%.*]], i32* align 16 dereferenceable(4) [[P:%.*]]) {
46+
; CHECK-NEXT: [[P_VAL:%.*]] = load i32, i32* [[P]], align 16
47+
; CHECK-NEXT: [[TMP1:%.*]] = call i32 @callee_guaranteed_aligned(i1 [[C]], i32 [[P_VAL]])
48+
; CHECK-NEXT: ret void
49+
;
50+
call i32 @callee_guaranteed_aligned(i1 %c, i32* %p)
51+
ret void
52+
}
53+
54+
; TODO: This should not be promoted, as the caller only guarantees that the
55+
; pointer is dereferenceable, not that it is aligned.
56+
define internal i32 @callee_not_guaranteed_aligned(i1 %c, i32* %p) {
57+
; CHECK-LABEL: define {{[^@]+}}@callee_not_guaranteed_aligned
58+
; CHECK-SAME: (i1 [[C:%.*]], i32 [[P_VAL:%.*]]) {
59+
; CHECK-NEXT: br i1 [[C]], label [[IF:%.*]], label [[ELSE:%.*]]
60+
; CHECK: if:
61+
; CHECK-NEXT: ret i32 [[P_VAL]]
62+
; CHECK: else:
63+
; CHECK-NEXT: ret i32 -1
64+
;
65+
br i1 %c, label %if, label %else
66+
67+
if:
68+
%x = load i32, i32* %p, align 16
69+
ret i32 %x
70+
71+
else:
72+
ret i32 -1
73+
}
74+
75+
define void @caller_not_guaranteed_aligned(i1 %c, i32* dereferenceable(4) %p) {
76+
; CHECK-LABEL: define {{[^@]+}}@caller_not_guaranteed_aligned
77+
; CHECK-SAME: (i1 [[C:%.*]], i32* dereferenceable(4) [[P:%.*]]) {
78+
; CHECK-NEXT: [[P_VAL:%.*]] = load i32, i32* [[P]], align 16
79+
; CHECK-NEXT: [[TMP1:%.*]] = call i32 @callee_not_guaranteed_aligned(i1 [[C]], i32 [[P_VAL]])
80+
; CHECK-NEXT: ret void
81+
;
82+
call i32 @callee_not_guaranteed_aligned(i1 %c, i32* %p)
83+
ret void
84+
}

0 commit comments

Comments
 (0)