Skip to content

Commit b8f3024

Browse files
authored
[InstCombine] Swap out range metadata to range attribute for cttz/ctlz/ctpop (#88776)
Since all optimizations that use range metadata now also handle range attribute, this patch replaces writes of range metadata for call instructions to range attributes.
1 parent ff57f40 commit b8f3024

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+515
-517
lines changed

clang/test/CodeGen/SystemZ/builtins-systemz-zvector.c

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2489,78 +2489,78 @@ void test_integer(void) {
24892489
// CHECK-ASM: vno
24902490

24912491
vuc = vec_cntlz(vsc);
2492-
// CHECK: call <16 x i8> @llvm.ctlz.v16i8(<16 x i8> %{{.*}}, i1 false)
2492+
// CHECK: call range(i8 0, 9) <16 x i8> @llvm.ctlz.v16i8(<16 x i8> %{{.*}}, i1 false)
24932493
// CHECK-ASM: vclzb
24942494
vuc = vec_cntlz(vuc);
2495-
// CHECK: call <16 x i8> @llvm.ctlz.v16i8(<16 x i8> %{{.*}}, i1 false)
2495+
// CHECK: call range(i8 0, 9) <16 x i8> @llvm.ctlz.v16i8(<16 x i8> %{{.*}}, i1 false)
24962496
// CHECK-ASM: vclzb
24972497
vus = vec_cntlz(vss);
2498-
// CHECK: call <8 x i16> @llvm.ctlz.v8i16(<8 x i16> %{{.*}}, i1 false)
2498+
// CHECK: call range(i16 0, 17) <8 x i16> @llvm.ctlz.v8i16(<8 x i16> %{{.*}}, i1 false)
24992499
// CHECK-ASM: vclzh
25002500
vus = vec_cntlz(vus);
2501-
// CHECK: call <8 x i16> @llvm.ctlz.v8i16(<8 x i16> %{{.*}}, i1 false)
2501+
// CHECK: call range(i16 0, 17) <8 x i16> @llvm.ctlz.v8i16(<8 x i16> %{{.*}}, i1 false)
25022502
// CHECK-ASM: vclzh
25032503
vui = vec_cntlz(vsi);
2504-
// CHECK: call <4 x i32> @llvm.ctlz.v4i32(<4 x i32> %{{.*}}, i1 false)
2504+
// CHECK: call range(i32 0, 33) <4 x i32> @llvm.ctlz.v4i32(<4 x i32> %{{.*}}, i1 false)
25052505
// CHECK-ASM: vclzf
25062506
vui = vec_cntlz(vui);
2507-
// CHECK: call <4 x i32> @llvm.ctlz.v4i32(<4 x i32> %{{.*}}, i1 false)
2507+
// CHECK: call range(i32 0, 33) <4 x i32> @llvm.ctlz.v4i32(<4 x i32> %{{.*}}, i1 false)
25082508
// CHECK-ASM: vclzf
25092509
vul = vec_cntlz(vsl);
2510-
// CHECK: call <2 x i64> @llvm.ctlz.v2i64(<2 x i64> %{{.*}}, i1 false)
2510+
// CHECK: call range(i64 0, 65) <2 x i64> @llvm.ctlz.v2i64(<2 x i64> %{{.*}}, i1 false)
25112511
// CHECK-ASM: vclzg
25122512
vul = vec_cntlz(vul);
2513-
// CHECK: call <2 x i64> @llvm.ctlz.v2i64(<2 x i64> %{{.*}}, i1 false)
2513+
// CHECK: call range(i64 0, 65) <2 x i64> @llvm.ctlz.v2i64(<2 x i64> %{{.*}}, i1 false)
25142514
// CHECK-ASM: vclzg
25152515

25162516
vuc = vec_cnttz(vsc);
2517-
// CHECK: call <16 x i8> @llvm.cttz.v16i8(<16 x i8> %{{.*}}, i1 false)
2517+
// CHECK: call range(i8 0, 9) <16 x i8> @llvm.cttz.v16i8(<16 x i8> %{{.*}}, i1 false)
25182518
// CHECK-ASM: vctzb
25192519
vuc = vec_cnttz(vuc);
2520-
// CHECK: call <16 x i8> @llvm.cttz.v16i8(<16 x i8> %{{.*}}, i1 false)
2520+
// CHECK: call range(i8 0, 9) <16 x i8> @llvm.cttz.v16i8(<16 x i8> %{{.*}}, i1 false)
25212521
// CHECK-ASM: vctzb
25222522
vus = vec_cnttz(vss);
2523-
// CHECK: call <8 x i16> @llvm.cttz.v8i16(<8 x i16> %{{.*}}, i1 false)
2523+
// CHECK: call range(i16 0, 17) <8 x i16> @llvm.cttz.v8i16(<8 x i16> %{{.*}}, i1 false)
25242524
// CHECK-ASM: vctzh
25252525
vus = vec_cnttz(vus);
2526-
// CHECK: call <8 x i16> @llvm.cttz.v8i16(<8 x i16> %{{.*}}, i1 false)
2526+
// CHECK: call range(i16 0, 17) <8 x i16> @llvm.cttz.v8i16(<8 x i16> %{{.*}}, i1 false)
25272527
// CHECK-ASM: vctzh
25282528
vui = vec_cnttz(vsi);
2529-
// CHECK: call <4 x i32> @llvm.cttz.v4i32(<4 x i32> %{{.*}}, i1 false)
2529+
// CHECK: call range(i32 0, 33) <4 x i32> @llvm.cttz.v4i32(<4 x i32> %{{.*}}, i1 false)
25302530
// CHECK-ASM: vctzf
25312531
vui = vec_cnttz(vui);
2532-
// CHECK: call <4 x i32> @llvm.cttz.v4i32(<4 x i32> %{{.*}}, i1 false)
2532+
// CHECK: call range(i32 0, 33) <4 x i32> @llvm.cttz.v4i32(<4 x i32> %{{.*}}, i1 false)
25332533
// CHECK-ASM: vctzf
25342534
vul = vec_cnttz(vsl);
2535-
// CHECK: call <2 x i64> @llvm.cttz.v2i64(<2 x i64> %{{.*}}, i1 false)
2535+
// CHECK: call range(i64 0, 65) <2 x i64> @llvm.cttz.v2i64(<2 x i64> %{{.*}}, i1 false)
25362536
// CHECK-ASM: vctzg
25372537
vul = vec_cnttz(vul);
2538-
// CHECK: call <2 x i64> @llvm.cttz.v2i64(<2 x i64> %{{.*}}, i1 false)
2538+
// CHECK: call range(i64 0, 65) <2 x i64> @llvm.cttz.v2i64(<2 x i64> %{{.*}}, i1 false)
25392539
// CHECK-ASM: vctzg
25402540

25412541
vuc = vec_popcnt(vsc);
2542-
// CHECK: call <16 x i8> @llvm.ctpop.v16i8(<16 x i8> %{{.*}})
2542+
// CHECK: call range(i8 0, 9) <16 x i8> @llvm.ctpop.v16i8(<16 x i8> %{{.*}})
25432543
// CHECK-ASM: vpopct
25442544
vuc = vec_popcnt(vuc);
2545-
// CHECK: call <16 x i8> @llvm.ctpop.v16i8(<16 x i8> %{{.*}})
2545+
// CHECK: call range(i8 0, 9) <16 x i8> @llvm.ctpop.v16i8(<16 x i8> %{{.*}})
25462546
// CHECK-ASM: vpopct
25472547
vus = vec_popcnt(vss);
2548-
// CHECK: call <8 x i16> @llvm.ctpop.v8i16(<8 x i16> %{{.*}})
2548+
// CHECK: call range(i16 0, 17) <8 x i16> @llvm.ctpop.v8i16(<8 x i16> %{{.*}})
25492549
// (emulated)
25502550
vus = vec_popcnt(vus);
2551-
// CHECK: call <8 x i16> @llvm.ctpop.v8i16(<8 x i16> %{{.*}})
2551+
// CHECK: call range(i16 0, 17) <8 x i16> @llvm.ctpop.v8i16(<8 x i16> %{{.*}})
25522552
// (emulated)
25532553
vui = vec_popcnt(vsi);
2554-
// CHECK: call <4 x i32> @llvm.ctpop.v4i32(<4 x i32> %{{.*}})
2554+
// CHECK: call range(i32 0, 33) <4 x i32> @llvm.ctpop.v4i32(<4 x i32> %{{.*}})
25552555
// (emulated)
25562556
vui = vec_popcnt(vui);
2557-
// CHECK: call <4 x i32> @llvm.ctpop.v4i32(<4 x i32> %{{.*}})
2557+
// CHECK: call range(i32 0, 33) <4 x i32> @llvm.ctpop.v4i32(<4 x i32> %{{.*}})
25582558
// (emulated)
25592559
vul = vec_popcnt(vsl);
2560-
// CHECK: call <2 x i64> @llvm.ctpop.v2i64(<2 x i64> %{{.*}})
2560+
// CHECK: call range(i64 0, 65) <2 x i64> @llvm.ctpop.v2i64(<2 x i64> %{{.*}})
25612561
// (emulated)
25622562
vul = vec_popcnt(vul);
2563-
// CHECK: call <2 x i64> @llvm.ctpop.v2i64(<2 x i64> %{{.*}})
2563+
// CHECK: call range(i64 0, 65) <2 x i64> @llvm.ctpop.v2i64(<2 x i64> %{{.*}})
25642564
// (emulated)
25652565

25662566
vsc = vec_rl(vsc, vuc);

clang/test/CodeGen/SystemZ/builtins-systemz-zvector2.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -577,28 +577,28 @@ void test_integer(void) {
577577
// CHECK-ASM: vnx
578578

579579
vuc = vec_popcnt(vsc);
580-
// CHECK: call <16 x i8> @llvm.ctpop.v16i8(<16 x i8> %{{.*}})
580+
// CHECK: call range(i8 0, 9) <16 x i8> @llvm.ctpop.v16i8(<16 x i8> %{{.*}})
581581
// CHECK-ASM: vpopctb
582582
vuc = vec_popcnt(vuc);
583-
// CHECK: call <16 x i8> @llvm.ctpop.v16i8(<16 x i8> %{{.*}})
583+
// CHECK: call range(i8 0, 9) <16 x i8> @llvm.ctpop.v16i8(<16 x i8> %{{.*}})
584584
// CHECK-ASM: vpopctb
585585
vus = vec_popcnt(vss);
586-
// CHECK: call <8 x i16> @llvm.ctpop.v8i16(<8 x i16> %{{.*}})
586+
// CHECK: call range(i16 0, 17) <8 x i16> @llvm.ctpop.v8i16(<8 x i16> %{{.*}})
587587
// CHECK-ASM: vpopcth
588588
vus = vec_popcnt(vus);
589-
// CHECK: call <8 x i16> @llvm.ctpop.v8i16(<8 x i16> %{{.*}})
589+
// CHECK: call range(i16 0, 17) <8 x i16> @llvm.ctpop.v8i16(<8 x i16> %{{.*}})
590590
// CHECK-ASM: vpopcth
591591
vui = vec_popcnt(vsi);
592-
// CHECK: call <4 x i32> @llvm.ctpop.v4i32(<4 x i32> %{{.*}})
592+
// CHECK: call range(i32 0, 33) <4 x i32> @llvm.ctpop.v4i32(<4 x i32> %{{.*}})
593593
// CHECK-ASM: vpopctf
594594
vui = vec_popcnt(vui);
595-
// CHECK: call <4 x i32> @llvm.ctpop.v4i32(<4 x i32> %{{.*}})
595+
// CHECK: call range(i32 0, 33) <4 x i32> @llvm.ctpop.v4i32(<4 x i32> %{{.*}})
596596
// CHECK-ASM: vpopctf
597597
vul = vec_popcnt(vsl);
598-
// CHECK: call <2 x i64> @llvm.ctpop.v2i64(<2 x i64> %{{.*}})
598+
// CHECK: call range(i64 0, 65) <2 x i64> @llvm.ctpop.v2i64(<2 x i64> %{{.*}})
599599
// CHECK-ASM: vpopctg
600600
vul = vec_popcnt(vul);
601-
// CHECK: call <2 x i64> @llvm.ctpop.v2i64(<2 x i64> %{{.*}})
601+
// CHECK: call range(i64 0, 65) <2 x i64> @llvm.ctpop.v2i64(<2 x i64> %{{.*}})
602602
// CHECK-ASM: vpopctg
603603

604604
vf = vec_slb(vf, vsi);

clang/test/CodeGen/builtins-wasm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ i32x4 bitselect(i32x4 x, i32x4 y, i32x4 c) {
406406

407407
i8x16 popcnt(i8x16 x) {
408408
return __builtin_wasm_popcnt_i8x16(x);
409-
// WEBASSEMBLY: call <16 x i8> @llvm.ctpop.v16i8(<16 x i8> %x)
409+
// WEBASSEMBLY: call range(i8 0, 9) <16 x i8> @llvm.ctpop.v16i8(<16 x i8> %x)
410410
// WEBASSEMBLY-NEXT: ret
411411
}
412412

clang/test/CodeGen/ms-intrinsics-other.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ unsigned char test_BitScanForward(unsigned LONG *Index, unsigned LONG Mask) {
5656
// CHECK: [[RESULT:%[a-z0-9._]+]] = phi i8 [ 0, %[[ISZERO_LABEL:[a-z0-9._]+]] ], [ 1, %[[ISNOTZERO_LABEL]] ]
5757
// CHECK: ret i8 [[RESULT]]
5858
// CHECK: [[ISNOTZERO_LABEL]]:
59-
// CHECK: [[INDEX:%[0-9]+]] = tail call i32 @llvm.cttz.i32(i32 %Mask, i1 true)
59+
// CHECK: [[INDEX:%[0-9]+]] = tail call range(i32 0, 33) i32 @llvm.cttz.i32(i32 %Mask, i1 true)
6060
// CHECK: store i32 [[INDEX]], ptr %Index, align 4
6161
// CHECK: br label %[[END_LABEL]]
6262

@@ -70,7 +70,7 @@ unsigned char test_BitScanReverse(unsigned LONG *Index, unsigned LONG Mask) {
7070
// CHECK: [[RESULT:%[a-z0-9._]+]] = phi i8 [ 0, %[[ISZERO_LABEL:[a-z0-9._]+]] ], [ 1, %[[ISNOTZERO_LABEL]] ]
7171
// CHECK: ret i8 [[RESULT]]
7272
// CHECK: [[ISNOTZERO_LABEL]]:
73-
// CHECK: [[REVINDEX:%[0-9]+]] = tail call i32 @llvm.ctlz.i32(i32 %Mask, i1 true)
73+
// CHECK: [[REVINDEX:%[0-9]+]] = tail call range(i32 0, 33) i32 @llvm.ctlz.i32(i32 %Mask, i1 true)
7474
// CHECK: [[INDEX:%[0-9]+]] = xor i32 [[REVINDEX]], 31
7575
// CHECK: store i32 [[INDEX]], ptr %Index, align 4
7676
// CHECK: br label %[[END_LABEL]]
@@ -86,7 +86,7 @@ unsigned char test_BitScanForward64(unsigned LONG *Index, unsigned __int64 Mask)
8686
// CHECK: [[RESULT:%[a-z0-9._]+]] = phi i8 [ 0, %[[ISZERO_LABEL:[a-z0-9._]+]] ], [ 1, %[[ISNOTZERO_LABEL]] ]
8787
// CHECK: ret i8 [[RESULT]]
8888
// CHECK: [[ISNOTZERO_LABEL]]:
89-
// CHECK: [[INDEX:%[0-9]+]] = tail call i64 @llvm.cttz.i64(i64 %Mask, i1 true)
89+
// CHECK: [[INDEX:%[0-9]+]] = tail call range(i64 0, 65) i64 @llvm.cttz.i64(i64 %Mask, i1 true)
9090
// CHECK: [[TRUNC_INDEX:%[0-9]+]] = trunc nuw nsw i64 [[INDEX]] to i32
9191
// CHECK: store i32 [[TRUNC_INDEX]], ptr %Index, align 4
9292
// CHECK: br label %[[END_LABEL]]
@@ -101,7 +101,7 @@ unsigned char test_BitScanReverse64(unsigned LONG *Index, unsigned __int64 Mask)
101101
// CHECK: [[RESULT:%[a-z0-9._]+]] = phi i8 [ 0, %[[ISZERO_LABEL:[a-z0-9._]+]] ], [ 1, %[[ISNOTZERO_LABEL]] ]
102102
// CHECK: ret i8 [[RESULT]]
103103
// CHECK: [[ISNOTZERO_LABEL]]:
104-
// CHECK: [[REVINDEX:%[0-9]+]] = tail call i64 @llvm.ctlz.i64(i64 %Mask, i1 true)
104+
// CHECK: [[REVINDEX:%[0-9]+]] = tail call range(i64 0, 65) i64 @llvm.ctlz.i64(i64 %Mask, i1 true)
105105
// CHECK: [[TRUNC_REVINDEX:%[0-9]+]] = trunc nuw nsw i64 [[REVINDEX]] to i32
106106
// CHECK: [[INDEX:%[0-9]+]] = xor i32 [[TRUNC_REVINDEX]], 63
107107
// CHECK: store i32 [[INDEX]], ptr %Index, align 4
@@ -187,47 +187,47 @@ unsigned short test__lzcnt16(unsigned short x) {
187187
return __lzcnt16(x);
188188
}
189189
// CHECK: i16 @test__lzcnt16
190-
// CHECK: [[RESULT:%[0-9]+]] = tail call i16 @llvm.ctlz.i16(i16 %x, i1 false)
190+
// CHECK: [[RESULT:%[0-9]+]] = tail call range(i16 0, 17) i16 @llvm.ctlz.i16(i16 %x, i1 false)
191191
// CHECK: ret i16 [[RESULT]]
192192
// CHECK: }
193193

194194
unsigned int test__lzcnt(unsigned int x) {
195195
return __lzcnt(x);
196196
}
197197
// CHECK: i32 @test__lzcnt
198-
// CHECK: [[RESULT:%[0-9]+]] = tail call i32 @llvm.ctlz.i32(i32 %x, i1 false)
198+
// CHECK: [[RESULT:%[0-9]+]] = tail call range(i32 0, 33) i32 @llvm.ctlz.i32(i32 %x, i1 false)
199199
// CHECK: ret i32 [[RESULT]]
200200
// CHECK: }
201201

202202
unsigned __int64 test__lzcnt64(unsigned __int64 x) {
203203
return __lzcnt64(x);
204204
}
205205
// CHECK: i64 @test__lzcnt64
206-
// CHECK: [[RESULT:%[0-9]+]] = tail call i64 @llvm.ctlz.i64(i64 %x, i1 false)
206+
// CHECK: [[RESULT:%[0-9]+]] = tail call range(i64 0, 65) i64 @llvm.ctlz.i64(i64 %x, i1 false)
207207
// CHECK: ret i64 [[RESULT]]
208208
// CHECK: }
209209

210210
unsigned short test__popcnt16(unsigned short x) {
211211
return __popcnt16(x);
212212
}
213213
// CHECK: i16 @test__popcnt16
214-
// CHECK: [[RESULT:%[0-9]+]] = tail call i16 @llvm.ctpop.i16(i16 %x)
214+
// CHECK: [[RESULT:%[0-9]+]] = tail call range(i16 0, 17) i16 @llvm.ctpop.i16(i16 %x)
215215
// CHECK: ret i16 [[RESULT]]
216216
// CHECK: }
217217

218218
unsigned int test__popcnt(unsigned int x) {
219219
return __popcnt(x);
220220
}
221221
// CHECK: i32 @test__popcnt
222-
// CHECK: [[RESULT:%[0-9]+]] = tail call i32 @llvm.ctpop.i32(i32 %x)
222+
// CHECK: [[RESULT:%[0-9]+]] = tail call range(i32 0, 33) i32 @llvm.ctpop.i32(i32 %x)
223223
// CHECK: ret i32 [[RESULT]]
224224
// CHECK: }
225225

226226
unsigned __int64 test__popcnt64(unsigned __int64 x) {
227227
return __popcnt64(x);
228228
}
229229
// CHECK: i64 @test__popcnt64
230-
// CHECK: [[RESULT:%[0-9]+]] = tail call i64 @llvm.ctpop.i64(i64 %x)
230+
// CHECK: [[RESULT:%[0-9]+]] = tail call range(i64 0, 65) i64 @llvm.ctpop.i64(i64 %x)
231231
// CHECK: ret i64 [[RESULT]]
232232
// CHECK: }
233233

clang/test/CodeGen/ms-intrinsics.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ unsigned char test_BitScanForward(unsigned long *Index, unsigned long Mask) {
157157
// CHECK: ret i8 [[RESULT]]
158158
// CHECK: [[ISNOTZERO_LABEL]]:
159159
// CHECK: [[IDXGEP:%[a-z0-9._]+]] = getelementptr inbounds i8, ptr %Index, {{i64|i32}} 4
160-
// CHECK: [[INDEX:%[0-9]+]] = tail call i32 @llvm.cttz.i32(i32 %Mask, i1 true)
160+
// CHECK: [[INDEX:%[0-9]+]] = tail call range(i32 0, 33) i32 @llvm.cttz.i32(i32 %Mask, i1 true)
161161
// CHECK: store i32 [[INDEX]], ptr [[IDXGEP]], align 4
162162
// CHECK: br label %[[END_LABEL]]
163163

@@ -172,7 +172,7 @@ unsigned char test_BitScanReverse(unsigned long *Index, unsigned long Mask) {
172172
// CHECK: ret i8 [[RESULT]]
173173
// CHECK: [[ISNOTZERO_LABEL]]:
174174
// CHECK: [[IDXGEP:%[a-z0-9._]+]] = getelementptr inbounds i8, ptr %Index, {{i64|i32}} 4
175-
// CHECK: [[REVINDEX:%[0-9]+]] = tail call i32 @llvm.ctlz.i32(i32 %Mask, i1 true)
175+
// CHECK: [[REVINDEX:%[0-9]+]] = tail call range(i32 0, 33) i32 @llvm.ctlz.i32(i32 %Mask, i1 true)
176176
// CHECK: [[INDEX:%[0-9]+]] = xor i32 [[REVINDEX]], 31
177177
// CHECK: store i32 [[INDEX]], ptr [[IDXGEP]], align 4
178178
// CHECK: br label %[[END_LABEL]]
@@ -188,7 +188,7 @@ unsigned char test_BitScanForward64(unsigned long *Index, unsigned __int64 Mask)
188188
// CHECK-ARM-X64: [[RESULT:%[a-z0-9._]+]] = phi i8 [ 0, %[[ISZERO_LABEL:[a-z0-9._]+]] ], [ 1, %[[ISNOTZERO_LABEL]] ]
189189
// CHECK-ARM-X64: ret i8 [[RESULT]]
190190
// CHECK-ARM-X64: [[ISNOTZERO_LABEL]]:
191-
// CHECK-ARM-X64: [[INDEX:%[0-9]+]] = tail call i64 @llvm.cttz.i64(i64 %Mask, i1 true)
191+
// CHECK-ARM-X64: [[INDEX:%[0-9]+]] = tail call range(i64 0, 65) i64 @llvm.cttz.i64(i64 %Mask, i1 true)
192192
// CHECK-ARM-X64: [[TRUNC_INDEX:%[0-9]+]] = trunc nuw nsw i64 [[INDEX]] to i32
193193
// CHECK-ARM-X64: store i32 [[TRUNC_INDEX]], ptr %Index, align 4
194194
// CHECK-ARM-X64: br label %[[END_LABEL]]
@@ -203,7 +203,7 @@ unsigned char test_BitScanReverse64(unsigned long *Index, unsigned __int64 Mask)
203203
// CHECK-ARM-X64: [[RESULT:%[a-z0-9._]+]] = phi i8 [ 0, %[[ISZERO_LABEL:[a-z0-9._]+]] ], [ 1, %[[ISNOTZERO_LABEL]] ]
204204
// CHECK-ARM-X64: ret i8 [[RESULT]]
205205
// CHECK-ARM-X64: [[ISNOTZERO_LABEL]]:
206-
// CHECK-ARM-X64: [[REVINDEX:%[0-9]+]] = tail call i64 @llvm.ctlz.i64(i64 %Mask, i1 true)
206+
// CHECK-ARM-X64: [[REVINDEX:%[0-9]+]] = tail call range(i64 0, 65) i64 @llvm.ctlz.i64(i64 %Mask, i1 true)
207207
// CHECK-ARM-X64: [[TRUNC_REVINDEX:%[0-9]+]] = trunc nuw nsw i64 [[REVINDEX]] to i32
208208
// CHECK-ARM-X64: [[INDEX:%[0-9]+]] = xor i32 [[TRUNC_REVINDEX]], 63
209209
// CHECK-ARM-X64: store i32 [[INDEX]], ptr %Index, align 4

clang/test/CodeGenOpenCL/builtins-generic-amdgcn.cl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
55

66
// CHECK-LABEL: @test_builtin_clz(
7-
// CHECK: tail call i32 @llvm.ctlz.i32(i32 %a, i1 true)
7+
// CHECK: tail call range(i32 0, 33) i32 @llvm.ctlz.i32(i32 %a, i1 true)
88
void test_builtin_clz(global int* out, int a)
99
{
1010
*out = __builtin_clz(a);
1111
}
1212

1313
// CHECK-LABEL: @test_builtin_clzl(
14-
// CHECK: tail call i64 @llvm.ctlz.i64(i64 %a, i1 true)
14+
// CHECK: tail call range(i64 0, 65) i64 @llvm.ctlz.i64(i64 %a, i1 true)
1515
void test_builtin_clzl(global long* out, long a)
1616
{
1717
*out = __builtin_clzl(a);

clang/test/Headers/wasm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1572,7 +1572,7 @@ uint32_t test_i8x16_bitmask(v128_t a) {
15721572
// CHECK-LABEL: @test_i8x16_popcnt(
15731573
// CHECK-NEXT: entry:
15741574
// CHECK-NEXT: [[TMP0:%.*]] = bitcast <4 x i32> [[A:%.*]] to <16 x i8>
1575-
// CHECK-NEXT: [[TMP1:%.*]] = tail call <16 x i8> @llvm.ctpop.v16i8(<16 x i8> [[TMP0]]), !range [[RNG5:![0-9]+]]
1575+
// CHECK-NEXT: [[TMP1:%.*]] = tail call range(i8 0, 9) <16 x i8> @llvm.ctpop.v16i8(<16 x i8> [[TMP0]])
15761576
// CHECK-NEXT: [[TMP2:%.*]] = bitcast <16 x i8> [[TMP1]] to <4 x i32>
15771577
// CHECK-NEXT: ret <4 x i32> [[TMP2]]
15781578
//

llvm/include/llvm/IR/Attributes.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,11 @@ class AttributeList {
747747
addDereferenceableOrNullParamAttr(LLVMContext &C, unsigned ArgNo,
748748
uint64_t Bytes) const;
749749

750+
/// Add the range attribute to the attribute set at the return value index.
751+
/// Returns a new list because attribute lists are immutable.
752+
[[nodiscard]] AttributeList addRangeRetAttr(LLVMContext &C,
753+
const ConstantRange &CR) const;
754+
750755
/// Add the allocsize attribute to the attribute set at the given arg index.
751756
/// Returns a new list because attribute lists are immutable.
752757
[[nodiscard]] AttributeList

llvm/include/llvm/IR/InstrTypes.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1941,6 +1941,11 @@ class CallBase : public Instruction {
19411941
Attrs = Attrs.addDereferenceableRetAttr(getContext(), Bytes);
19421942
}
19431943

1944+
/// adds the range attribute to the list of attributes.
1945+
void addRangeRetAttr(const ConstantRange &CR) {
1946+
Attrs = Attrs.addRangeRetAttr(getContext(), CR);
1947+
}
1948+
19441949
/// Determine whether the return value has the given attribute.
19451950
bool hasRetAttr(Attribute::AttrKind Kind) const {
19461951
return hasRetAttrImpl(Kind);

llvm/lib/IR/Attributes.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,6 +1530,13 @@ AttributeList::addDereferenceableOrNullParamAttr(LLVMContext &C, unsigned Index,
15301530
return addParamAttributes(C, Index, B);
15311531
}
15321532

1533+
AttributeList AttributeList::addRangeRetAttr(LLVMContext &C,
1534+
const ConstantRange &CR) const {
1535+
AttrBuilder B(C);
1536+
B.addRangeAttr(CR);
1537+
return addRetAttributes(C, B);
1538+
}
1539+
15331540
AttributeList AttributeList::addAllocSizeParamAttr(
15341541
LLVMContext &C, unsigned Index, unsigned ElemSizeArg,
15351542
const std::optional<unsigned> &NumElemsArg) {

llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -606,14 +606,13 @@ static Instruction *foldCttzCtlz(IntrinsicInst &II, InstCombinerImpl &IC) {
606606
return IC.replaceOperand(II, 1, IC.Builder.getTrue());
607607
}
608608

609-
// Add range metadata since known bits can't completely reflect what we know.
610-
auto *IT = cast<IntegerType>(Op0->getType()->getScalarType());
611-
if (IT && IT->getBitWidth() != 1 && !II.getMetadata(LLVMContext::MD_range)) {
612-
Metadata *LowAndHigh[] = {
613-
ConstantAsMetadata::get(ConstantInt::get(IT, DefiniteZeros)),
614-
ConstantAsMetadata::get(ConstantInt::get(IT, PossibleZeros + 1))};
615-
II.setMetadata(LLVMContext::MD_range,
616-
MDNode::get(II.getContext(), LowAndHigh));
609+
// Add range attribute since known bits can't completely reflect what we know.
610+
unsigned BitWidth = Op0->getType()->getScalarSizeInBits();
611+
if (BitWidth != 1 && !II.hasRetAttr(Attribute::Range) &&
612+
!II.getMetadata(LLVMContext::MD_range)) {
613+
ConstantRange Range(APInt(BitWidth, DefiniteZeros),
614+
APInt(BitWidth, PossibleZeros + 1));
615+
II.addRangeRetAttr(Range);
617616
return &II;
618617
}
619618

@@ -685,16 +684,12 @@ static Instruction *foldCtpop(IntrinsicInst &II, InstCombinerImpl &IC) {
685684
Constant::getNullValue(Ty)),
686685
Ty);
687686

688-
// Add range metadata since known bits can't completely reflect what we know.
689-
auto *IT = cast<IntegerType>(Ty->getScalarType());
690-
unsigned MinCount = Known.countMinPopulation();
691-
unsigned MaxCount = Known.countMaxPopulation();
692-
if (IT->getBitWidth() != 1 && !II.getMetadata(LLVMContext::MD_range)) {
693-
Metadata *LowAndHigh[] = {
694-
ConstantAsMetadata::get(ConstantInt::get(IT, MinCount)),
695-
ConstantAsMetadata::get(ConstantInt::get(IT, MaxCount + 1))};
696-
II.setMetadata(LLVMContext::MD_range,
697-
MDNode::get(II.getContext(), LowAndHigh));
687+
// Add range attribute since known bits can't completely reflect what we know.
688+
if (BitWidth != 1 && !II.hasRetAttr(Attribute::Range) &&
689+
!II.getMetadata(LLVMContext::MD_range)) {
690+
ConstantRange Range(APInt(BitWidth, Known.countMinPopulation()),
691+
APInt(BitWidth, Known.countMaxPopulation() + 1));
692+
II.addRangeRetAttr(Range);
698693
return &II;
699694
}
700695

0 commit comments

Comments
 (0)