@@ -65,7 +65,6 @@ define i32 @interfering_lifetime(ptr %data, i64 %indvars.iv) {
65
65
; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr [[DATA:%.*]], i64 [[INDVARS_IV:%.*]]
66
66
; CHECK-NEXT: [[I1:%.*]] = load i32, ptr [[ARRAYIDX]], align 4
67
67
; CHECK-NEXT: [[CMP_I_I:%.*]] = icmp slt i32 [[I1]], 0
68
- ; CHECK-NEXT: [[I2:%.*]] = tail call i32 @llvm.smax.i32(i32 [[I1]], i32 0)
69
68
; CHECK-NEXT: [[I3_SROA_SPECULATE_LOAD_FALSE:%.*]] = load i32, ptr [[ARRAYIDX]], align 4
70
69
; CHECK-NEXT: [[I3_SROA_SPECULATED:%.*]] = select i1 [[CMP_I_I]], i32 0, i32 [[I3_SROA_SPECULATE_LOAD_FALSE]]
71
70
; CHECK-NEXT: ret i32 [[I3_SROA_SPECULATED]]
@@ -76,7 +75,6 @@ define i32 @interfering_lifetime(ptr %data, i64 %indvars.iv) {
76
75
call void @llvm.lifetime.start.p0 (i64 4 , ptr %min )
77
76
store i32 0 , ptr %min , align 4
78
77
%cmp.i.i = icmp slt i32 %i1 , 0
79
- %i2 = tail call i32 @llvm.smax.i32 (i32 %i1 , i32 0 )
80
78
%__b.__a.i.i = select i1 %cmp.i.i , ptr %min , ptr %arrayidx
81
79
%i3 = load i32 , ptr %__b.__a.i.i , align 4
82
80
ret i32 %i3
@@ -118,6 +116,44 @@ define i32 @clamp_load_to_constant_range(ptr %data, i64 %indvars.iv) {
118
116
ret i32 %i3
119
117
}
120
118
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
+
121
157
declare void @llvm.lifetime.start.p0 (i64 , ptr )
122
158
declare void @llvm.lifetime.end.p0 (i64 , ptr )
123
159
declare i32 @llvm.smax.i32 (i32 , i32 )
0 commit comments