Skip to content

Commit 950f248

Browse files
committed
[NFC][SROA] Add more tests with non-speculatable loads of selects
1 parent ee74d37 commit 950f248

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

llvm/test/Transforms/SROA/select-load.ll

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ define i32 @interfering_lifetime(ptr %data, i64 %indvars.iv) {
6565
; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr [[DATA:%.*]], i64 [[INDVARS_IV:%.*]]
6666
; CHECK-NEXT: [[I1:%.*]] = load i32, ptr [[ARRAYIDX]], align 4
6767
; CHECK-NEXT: [[CMP_I_I:%.*]] = icmp slt i32 [[I1]], 0
68-
; CHECK-NEXT: [[I2:%.*]] = tail call i32 @llvm.smax.i32(i32 [[I1]], i32 0)
6968
; CHECK-NEXT: [[I3_SROA_SPECULATE_LOAD_FALSE:%.*]] = load i32, ptr [[ARRAYIDX]], align 4
7069
; CHECK-NEXT: [[I3_SROA_SPECULATED:%.*]] = select i1 [[CMP_I_I]], i32 0, i32 [[I3_SROA_SPECULATE_LOAD_FALSE]]
7170
; CHECK-NEXT: ret i32 [[I3_SROA_SPECULATED]]
@@ -76,7 +75,6 @@ define i32 @interfering_lifetime(ptr %data, i64 %indvars.iv) {
7675
call void @llvm.lifetime.start.p0(i64 4, ptr %min)
7776
store i32 0, ptr %min, align 4
7877
%cmp.i.i = icmp slt i32 %i1, 0
79-
%i2 = tail call i32 @llvm.smax.i32(i32 %i1, i32 0)
8078
%__b.__a.i.i = select i1 %cmp.i.i, ptr %min, ptr %arrayidx
8179
%i3 = load i32, ptr %__b.__a.i.i, align 4
8280
ret i32 %i3
@@ -118,6 +116,44 @@ define i32 @clamp_load_to_constant_range(ptr %data, i64 %indvars.iv) {
118116
ret i32 %i3
119117
}
120118

119+
define i32 @non_speculatable_load_of_select(i1 %cond, ptr %data) {
120+
; CHECK-LABEL: @non_speculatable_load_of_select(
121+
; CHECK-NEXT: entry:
122+
; CHECK-NEXT: [[MIN:%.*]] = alloca i32, align 4
123+
; CHECK-NEXT: store i32 0, ptr [[MIN]], align 4
124+
; CHECK-NEXT: [[ADDR:%.*]] = select i1 [[COND:%.*]], ptr [[MIN]], ptr [[DATA:%.*]], !prof [[PROF0:![0-9]+]]
125+
; CHECK-NEXT: [[R:%.*]] = load i32, ptr [[ADDR]], align 4
126+
; CHECK-NEXT: ret i32 [[R]]
127+
;
128+
entry:
129+
%min = alloca i32, align 4
130+
store i32 0, ptr %min, align 4
131+
%addr = select i1 %cond, ptr %min, ptr %data, !prof !0
132+
%r = load i32, ptr %addr, align 4
133+
ret i32 %r
134+
}
135+
define i32 @non_speculatable_load_of_select_inverted(i1 %cond, ptr %data) {
136+
; CHECK-LABEL: @non_speculatable_load_of_select_inverted(
137+
; CHECK-NEXT: entry:
138+
; CHECK-NEXT: [[MAX:%.*]] = alloca i32, align 4
139+
; CHECK-NEXT: store i32 4095, ptr [[MAX]], align 4
140+
; CHECK-NEXT: [[ADDR:%.*]] = select i1 [[COND:%.*]], ptr [[DATA:%.*]], ptr [[MAX]], !prof [[PROF0]]
141+
; CHECK-NEXT: [[R:%.*]] = load i32, ptr [[ADDR]], align 4
142+
; CHECK-NEXT: ret i32 [[R]]
143+
;
144+
entry:
145+
%max = alloca i32, align 4
146+
store i32 4095, ptr %max, align 4
147+
%addr = select i1 %cond, ptr %data, ptr %max, !prof !0
148+
%r = load i32, ptr %addr, align 4
149+
ret i32 %r
150+
}
151+
152+
!0 = !{!"branch_weights", i32 1, i32 99}
153+
154+
; Ensure that the branch metadata is reversed to match the reversals above.
155+
; CHECK: !0 = {{.*}} i32 1, i32 99}
156+
121157
declare void @llvm.lifetime.start.p0(i64, ptr )
122158
declare void @llvm.lifetime.end.p0(i64, ptr)
123159
declare i32 @llvm.smax.i32(i32, i32)

0 commit comments

Comments
 (0)