Skip to content

Commit 954420c

Browse files
committed
Use getMinSignedBits and add a few more tests
1 parent fbe5f0e commit 954420c

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

llvm/lib/Target/X86/X86InstrCompiler.td

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,8 +1264,7 @@ def inRange32GlobalAddr : PatLeaf<(tglobaladdr:$dst), [{
12641264
std::optional<ConstantRange> CR = GA->getGlobal()->getAbsoluteSymbolRange();
12651265
if (!CR)
12661266
return true;
1267-
return CR->getSignedMin().sge(-1ull << 32) &&
1268-
CR->getSignedMax().slt(1ull << 32);
1267+
return CR->getMinSignedBits() <= 32;
12691268
}]>;
12701269
def : Pat<(i64 (X86Wrapper inRange32GlobalAddr:$dst)),
12711270
(MOV64ri32 tglobaladdr:$dst)>, Requires<[KernelCode]>;

llvm/test/CodeGen/X86/absolute-symbol-kernel-code-model.ll

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,48 @@
22

33
target triple = "x86_64-unknown-linux-gnu"
44

5+
; CHECK-LABEL: func_no_abs_sym
6+
define i64 @func_no_abs_sym() nounwind {
7+
; CHECK: movq $no_abs_sym, %rax
8+
%1 = ptrtoint ptr @no_abs_sym to i64
9+
ret i64 %1
10+
}
11+
512
; CHECK-LABEL: func_abs_sym
613
define i64 @func_abs_sym() nounwind {
714
; CHECK: movabsq $abs_sym, %rax
815
%1 = ptrtoint ptr @abs_sym to i64
916
ret i64 %1
1017
}
1118

12-
; CHECK-LABEL: func_no_abs_sym
13-
define i64 @func_no_abs_sym() nounwind {
14-
; CHECK: movq $no_abs_sym, %rax
15-
%1 = ptrtoint ptr @no_abs_sym to i64
19+
; CHECK-LABEL: func_abs_sym_in_range
20+
define i64 @func_abs_sym_in_range() nounwind {
21+
; CHECK: movq $abs_sym_in_range, %rax
22+
%1 = ptrtoint ptr @abs_sym_in_range to i64
23+
ret i64 %1
24+
}
25+
26+
; CHECK-LABEL: func_abs_sym_min_out_of_range
27+
define i64 @func_abs_sym_min_out_of_range() nounwind {
28+
; CHECK: movabsq $abs_sym_min_out_of_range, %rax
29+
%1 = ptrtoint ptr @abs_sym_min_out_of_range to i64
30+
ret i64 %1
31+
}
32+
33+
; CHECK-LABEL: func_abs_sym_max_out_of_range
34+
define i64 @func_abs_sym_max_out_of_range() nounwind {
35+
; CHECK: movabsq $abs_sym_max_out_of_range, %rax
36+
%1 = ptrtoint ptr @abs_sym_max_out_of_range to i64
1637
ret i64 %1
1738
}
1839

19-
@abs_sym = external hidden global [0 x i8], !absolute_symbol !0
2040
@no_abs_sym = external hidden global [0 x i8]
41+
@abs_sym = external hidden global [0 x i8], !absolute_symbol !0
42+
@abs_sym_in_range = external hidden global [0 x i8], !absolute_symbol !1
43+
@abs_sym_min_out_of_range = external hidden global [0 x i8], !absolute_symbol !2
44+
@abs_sym_max_out_of_range = external hidden global [0 x i8], !absolute_symbol !3
2145

22-
!0 = !{i64 -1, i64 -1}
46+
!0 = !{i64 -1, i64 -1} ;; Full range
47+
!1 = !{i64 -2147483648, i64 2147483648} ;; Note the upper bound is exclusive.
48+
!2 = !{i64 -2147483649, i64 2147483648} ;; Min is one below -2^31
49+
!3 = !{i64 -2147483648, i64 2147483649} ;; Max is one above 2^31-1

0 commit comments

Comments
 (0)