1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
|
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -indvars -S | FileCheck %s
@array = dso_local global [16777219 x i32] zeroinitializer, align 4
define void @sitofp_fptosi_range() {
; CHECK-LABEL: @sitofp_fptosi_range(
; CHECK-NEXT: entry:
; CHECK-NEXT: br label [[FOR_BODY:%.*]]
; CHECK: for.body:
; CHECK-NEXT: [[IV_INT:%.*]] = phi i32 [ 100, [[ENTRY:%.*]] ], [ [[DEC_INT:%.*]], [[FOR_BODY]] ]
; CHECK-NEXT: [[IDXPROM:%.*]] = sext i32 [[IV_INT]] to i64
; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds [16777219 x i32], [16777219 x i32]* @array, i64 0, i64 [[IDXPROM]]
; CHECK-NEXT: store i32 [[IV_INT]], i32* [[ARRAYIDX]], align 4
; CHECK-NEXT: [[DEC_INT]] = add nsw i32 [[IV_INT]], -1
; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i32 [[DEC_INT]], 0
; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[CLEANUP:%.*]]
; CHECK: cleanup:
; CHECK-NEXT: ret void
;
entry:
br label %for.body
for.body: ; preds = %for.body, %entry
%iv.int = phi i32 [ 100, %entry ], [ %dec.int, %for.body ]
%indvar.conv = sitofp i32 %iv.int to float
%conv = fptosi float %indvar.conv to i32
%idxprom = sext i32 %conv to i64
%arrayidx = getelementptr inbounds [16777219 x i32], [16777219 x i32]* @array, i64 0, i64 %idxprom
store i32 %conv, i32* %arrayidx, align 4
%dec.int = add nsw i32 %iv.int, -1
%cmp = icmp ugt i32 %dec.int, 0
br i1 %cmp, label %for.body, label %cleanup
cleanup: ; preds = %for.body
ret void
}
; Negative test: The transform is *not* valid because there are too many significant bits
define void @sitofp_fptosi_range_overflow() {
; CHECK-LABEL: @sitofp_fptosi_range_overflow(
; CHECK-NEXT: entry:
; CHECK-NEXT: br label [[FOR_BODY:%.*]]
; CHECK: for.body:
; CHECK-NEXT: [[IV_INT:%.*]] = phi i32 [ 16777218, [[ENTRY:%.*]] ], [ [[DEC_INT:%.*]], [[FOR_BODY]] ]
; CHECK-NEXT: [[INDVAR_CONV:%.*]] = sitofp i32 [[IV_INT]] to float
; CHECK-NEXT: [[CONV:%.*]] = fptosi float [[INDVAR_CONV]] to i32
; CHECK-NEXT: [[IDXPROM:%.*]] = sext i32 [[CONV]] to i64
; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds [16777219 x i32], [16777219 x i32]* @array, i64 0, i64 [[IDXPROM]]
; CHECK-NEXT: store i32 [[CONV]], i32* [[ARRAYIDX]], align 4
; CHECK-NEXT: [[DEC_INT]] = add nsw i32 [[IV_INT]], -1
; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i32 [[DEC_INT]], 0
; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[CLEANUP:%.*]]
; CHECK: cleanup:
; CHECK-NEXT: ret void
;
entry:
br label %for.body
for.body: ; preds = %for.body, %entry
%iv.int = phi i32 [ 16777218, %entry ], [ %dec.int, %for.body ] ; intermediate 16777218 (= 1 << 24 + 2)
%indvar.conv = sitofp i32 %iv.int to float
%conv = fptosi float %indvar.conv to i32
%idxprom = sext i32 %conv to i64
%arrayidx = getelementptr inbounds [16777219 x i32], [16777219 x i32]* @array, i64 0, i64 %idxprom
store i32 %conv, i32* %arrayidx, align 4
%dec.int = add nsw i32 %iv.int, -1
%cmp = icmp ugt i32 %dec.int, 0
br i1 %cmp, label %for.body, label %cleanup
cleanup: ; preds = %for.body
ret void
}
; Negative test: Type mismatch between the integer IV and the fptosi result
define void @sitofp_fptosi_range_mismatch_type() {
;
; CHECK-LABEL: @sitofp_fptosi_range_mismatch_type(
; CHECK-NEXT: entry:
; CHECK-NEXT: br label [[FOR_BODY:%.*]]
; CHECK: for.body:
; CHECK-NEXT: [[IV_INT:%.*]] = phi i32 [ 100, [[ENTRY:%.*]] ], [ [[DEC_INT:%.*]], [[FOR_BODY]] ]
; CHECK-NEXT: [[INDVAR_CONV:%.*]] = sitofp i32 [[IV_INT]] to float
; CHECK-NEXT: [[CONV:%.*]] = fptosi float [[INDVAR_CONV]] to i16
; CHECK-NEXT: [[IDXPROM32:%.*]] = sext i16 [[CONV]] to i32
; CHECK-NEXT: [[IDXPROM64:%.*]] = sext i16 [[CONV]] to i64
; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds [16777219 x i32], [16777219 x i32]* @array, i64 0, i64 [[IDXPROM64]]
; CHECK-NEXT: store i32 [[IDXPROM32]], i32* [[ARRAYIDX]], align 4
; CHECK-NEXT: [[DEC_INT]] = add nsw i32 [[IV_INT]], -1
; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i32 [[DEC_INT]], 0
; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[CLEANUP:%.*]]
; CHECK: cleanup:
; CHECK-NEXT: ret void
;
entry:
br label %for.body
for.body: ; preds = %for.body, %entry
%iv.int = phi i32 [ 100, %entry ], [ %dec.int, %for.body ]
%indvar.conv = sitofp i32 %iv.int to float
%conv = fptosi float %indvar.conv to i16
%idxprom32 = sext i16 %conv to i32
%idxprom64 = sext i16 %conv to i64
%arrayidx = getelementptr inbounds [16777219 x i32], [16777219 x i32]* @array, i64 0, i64 %idxprom64
store i32 %idxprom32, i32* %arrayidx, align 4
%dec.int = add nsw i32 %iv.int, -1
%cmp = icmp ugt i32 %dec.int, 0
br i1 %cmp, label %for.body, label %cleanup
cleanup: ; preds = %for.body
ret void
}
define void @sitofp_fptoui_range() {
; CHECK-LABEL: @sitofp_fptoui_range(
; CHECK-NEXT: entry:
; CHECK-NEXT: br label [[FOR_BODY:%.*]]
; CHECK: for.body:
; CHECK-NEXT: [[IV_INT:%.*]] = phi i32 [ 100, [[ENTRY:%.*]] ], [ [[DEC_INT:%.*]], [[FOR_BODY]] ]
; CHECK-NEXT: [[IDXPROM:%.*]] = zext i32 [[IV_INT]] to i64
; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds [16777219 x i32], [16777219 x i32]* @array, i64 0, i64 [[IDXPROM]]
; CHECK-NEXT: store i32 [[IV_INT]], i32* [[ARRAYIDX]], align 4
; CHECK-NEXT: [[DEC_INT]] = add nsw i32 [[IV_INT]], -1
; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i32 [[DEC_INT]], 0
; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[CLEANUP:%.*]]
; CHECK: cleanup:
; CHECK-NEXT: ret void
;
entry:
br label %for.body
for.body: ; preds = %for.body, %entry
%iv.int = phi i32 [ 100, %entry ], [ %dec.int, %for.body ]
%indvar.conv = sitofp i32 %iv.int to float
%conv = fptoui float %indvar.conv to i32
%idxprom = zext i32 %conv to i64
%arrayidx = getelementptr inbounds [16777219 x i32], [16777219 x i32]* @array, i64 0, i64 %idxprom
store i32 %conv, i32* %arrayidx, align 4
%dec.int = add nsw i32 %iv.int, -1
%cmp = icmp sgt i32 %dec.int, 0
br i1 %cmp, label %for.body, label %cleanup
cleanup: ; preds = %for.body
ret void
}
; Range including negative value.
define void @sitofp_fptoui_range_with_negative () {
; CHECK-LABEL: @sitofp_fptoui_range_with_negative(
; CHECK-NEXT: entry:
; CHECK-NEXT: br label [[FOR_BODY:%.*]]
; CHECK: for.body:
; CHECK-NEXT: [[IV_INT:%.*]] = phi i32 [ 100, [[ENTRY:%.*]] ], [ [[DEC_INT:%.*]], [[FOR_BODY]] ]
; CHECK-NEXT: [[IDXPROM:%.*]] = zext i32 [[IV_INT]] to i64
; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds [16777219 x i32], [16777219 x i32]* @array, i64 0, i64 [[IDXPROM]]
; CHECK-NEXT: store i32 [[IV_INT]], i32* [[ARRAYIDX]], align 4
; CHECK-NEXT: [[DEC_INT]] = add nsw i32 [[IV_INT]], -1
; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[DEC_INT]], -100
; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[CLEANUP:%.*]]
; CHECK: cleanup:
; CHECK-NEXT: ret void
;
entry:
br label %for.body
for.body: ; preds = %for.body, %entry
%iv.int = phi i32 [ 100, %entry ], [ %dec.int, %for.body ]
%indvar.conv = sitofp i32 %iv.int to float
%conv = fptoui float %indvar.conv to i32
%idxprom = zext i32 %conv to i64
%arrayidx = getelementptr inbounds [16777219 x i32], [16777219 x i32]* @array, i64 0, i64 %idxprom
store i32 %conv, i32* %arrayidx, align 4
%dec.int = add nsw i32 %iv.int, -1
%cmp = icmp sgt i32 %dec.int, -100
br i1 %cmp, label %for.body, label %cleanup
cleanup: ; preds = %for.body
ret void
}
; https://godbolt.org/z/51MrqYjEf
define void @uitofp_fptoui_range () {
; CHECK-LABEL: @uitofp_fptoui_range(
; CHECK-NEXT: entry:
; CHECK-NEXT: br label [[FOR_BODY:%.*]]
; CHECK: for.body:
; CHECK-NEXT: [[IV_INT:%.*]] = phi i32 [ 100, [[ENTRY:%.*]] ], [ [[DEC_INT:%.*]], [[FOR_BODY]] ]
; CHECK-NEXT: [[IDXPROM:%.*]] = zext i32 [[IV_INT]] to i64
; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds [16777219 x i32], [16777219 x i32]* @array, i64 0, i64 [[IDXPROM]]
; CHECK-NEXT: store i32 [[IV_INT]], i32* [[ARRAYIDX]], align 4
; CHECK-NEXT: [[DEC_INT]] = add nsw i32 [[IV_INT]], -1
; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i32 [[DEC_INT]], 3
; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[CLEANUP:%.*]]
; CHECK: cleanup:
; CHECK-NEXT: ret void
;
entry:
br label %for.body
for.body: ; preds = %for.body, %entry
%iv.int = phi i32 [ 100, %entry ], [ %dec.int, %for.body ]
%indvar.conv = uitofp i32 %iv.int to float
%conv = fptoui float %indvar.conv to i32
%idxprom = zext i32 %conv to i64
%arrayidx = getelementptr inbounds [16777219 x i32], [16777219 x i32]* @array, i64 0, i64 %idxprom
store i32 %conv, i32* %arrayidx, align 4
%dec.int = add nsw i32 %iv.int, -1
%cmp = icmp ugt i32 %dec.int, 3
br i1 %cmp, label %for.body, label %cleanup
cleanup: ; preds = %for.body
ret void
}
define void @uitofp_fptoui_range_with_negative() {
; CHECK-LABEL: @uitofp_fptoui_range_with_negative(
; CHECK-NEXT: entry:
; CHECK-NEXT: br label [[FOR_BODY:%.*]]
; CHECK: for.body:
; CHECK-NEXT: store i32 100, i32* getelementptr inbounds ([16777219 x i32], [16777219 x i32]* @array, i64 0, i64 100), align 4
; CHECK-NEXT: br i1 false, label [[FOR_BODY]], label [[CLEANUP:%.*]]
; CHECK: cleanup:
; CHECK-NEXT: ret void
;
entry:
br label %for.body
for.body: ; preds = %for.body, %entry
%iv.int = phi i32 [ 100, %entry ], [ %dec.int, %for.body ]
%indvar.conv = uitofp i32 %iv.int to float
%conv = fptoui float %indvar.conv to i32
%idxprom = zext i32 %conv to i64
%arrayidx = getelementptr inbounds [16777219 x i32], [16777219 x i32]* @array, i64 0, i64 %idxprom
store i32 %conv, i32* %arrayidx, align 4
%dec.int = add nsw i32 %iv.int, -1
%cmp = icmp ugt i32 %dec.int, -100
br i1 %cmp, label %for.body, label %cleanup
cleanup: ; preds = %for.body
ret void
}
define void @uitofp_fptosi_range () {
; CHECK-LABEL: @uitofp_fptosi_range(
; CHECK-NEXT: entry:
; CHECK-NEXT: br label [[FOR_BODY:%.*]]
; CHECK: for.body:
; CHECK-NEXT: [[IV_INT:%.*]] = phi i32 [ 100, [[ENTRY:%.*]] ], [ [[DEC_INT:%.*]], [[FOR_BODY]] ]
; CHECK-NEXT: [[IDXPROM:%.*]] = sext i32 [[IV_INT]] to i64
; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds [16777219 x i32], [16777219 x i32]* @array, i64 0, i64 [[IDXPROM]]
; CHECK-NEXT: store i32 [[IV_INT]], i32* [[ARRAYIDX]], align 4
; CHECK-NEXT: [[DEC_INT]] = add nsw i32 [[IV_INT]], -1
; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i32 [[DEC_INT]], 3
; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[CLEANUP:%.*]]
; CHECK: cleanup:
; CHECK-NEXT: ret void
;
entry:
br label %for.body
for.body: ; preds = %for.body, %entry
%iv.int = phi i32 [ 100, %entry ], [ %dec.int, %for.body ]
%indvar.conv = uitofp i32 %iv.int to float
%conv = fptosi float %indvar.conv to i32
%idxprom = sext i32 %conv to i64
%arrayidx = getelementptr inbounds [16777219 x i32], [16777219 x i32]* @array, i64 0, i64 %idxprom
store i32 %conv, i32* %arrayidx, align 4
%dec.int = add nsw i32 %iv.int, -1
%cmp = icmp ugt i32 %dec.int, 3
br i1 %cmp, label %for.body, label %cleanup
cleanup: ; preds = %for.body
ret void
}
define void @uitofp_fptosi_range_with_negative () {
; CHECK-LABEL: @uitofp_fptosi_range_with_negative(
; CHECK-NEXT: entry:
; CHECK-NEXT: br label [[FOR_BODY:%.*]]
; CHECK: for.body:
; CHECK-NEXT: store i32 100, i32* getelementptr inbounds ([16777219 x i32], [16777219 x i32]* @array, i64 0, i64 100), align 4
; CHECK-NEXT: br i1 false, label [[FOR_BODY]], label [[CLEANUP:%.*]]
; CHECK: cleanup:
; CHECK-NEXT: ret void
;
entry:
br label %for.body
for.body: ; preds = %for.body, %entry
%iv.int = phi i32 [ 100, %entry ], [ %dec.int, %for.body ]
%indvar.conv = uitofp i32 %iv.int to float
%conv = fptosi float %indvar.conv to i32
%idxprom = sext i32 %conv to i64
%arrayidx = getelementptr inbounds [16777219 x i32], [16777219 x i32]* @array, i64 0, i64 %idxprom
store i32 %conv, i32* %arrayidx, align 4
%dec.int = add nsw i32 %iv.int, -1
%cmp = icmp ugt i32 %dec.int, -100
br i1 %cmp, label %for.body, label %cleanup
cleanup: ; preds = %for.body
ret void
}
|