Skip to content

Commit ddc2311

Browse files
committed
Just check for getAbsoluteSymbolRange since there's no benefit to using the sign extending instruction with absolute symbols.
1 parent 954420c commit ddc2311

File tree

2 files changed

+8
-26
lines changed

2 files changed

+8
-26
lines changed

llvm/lib/Target/X86/X86InstrCompiler.td

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,14 +1257,11 @@ def : Pat<(i64 (X86Wrapper tconstpool :$dst)),
12571257
def : Pat<(i64 (X86Wrapper tjumptable :$dst)),
12581258
(MOV64ri32 tjumptable :$dst)>, Requires<[KernelCode]>;
12591259

1260-
// If the globaladdr has an absolute_symbol range, we should assert it would
1261-
// fit into a 32-bit offset.
1260+
// If the globaladdr is an absolute_symbol, don't bother using the sign extending
1261+
// instruction since there's no benefit to using it with absolute symbols.
12621262
def inRange32GlobalAddr : PatLeaf<(tglobaladdr:$dst), [{
12631263
auto *GA = cast<GlobalAddressSDNode>(N);
1264-
std::optional<ConstantRange> CR = GA->getGlobal()->getAbsoluteSymbolRange();
1265-
if (!CR)
1266-
return true;
1267-
return CR->getMinSignedBits() <= 32;
1264+
return !GA->getGlobal()->getAbsoluteSymbolRange();
12681265
}]>;
12691266
def : Pat<(i64 (X86Wrapper inRange32GlobalAddr:$dst)),
12701267
(MOV64ri32 tglobaladdr:$dst)>, Requires<[KernelCode]>;

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

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,17 @@ define i64 @func_abs_sym() nounwind {
1818

1919
; CHECK-LABEL: func_abs_sym_in_range
2020
define i64 @func_abs_sym_in_range() nounwind {
21-
; CHECK: movq $abs_sym_in_range, %rax
21+
;; The absolute_symbol range fits in 32 bits but we still use movabs
22+
;; since there's no benefit to using the sign extending instruction
23+
;; with absolute symbols.
24+
; CHECK: movabsq $abs_sym_in_range, %rax
2225
%1 = ptrtoint ptr @abs_sym_in_range to i64
2326
ret i64 %1
2427
}
2528

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
37-
ret i64 %1
38-
}
39-
4029
@no_abs_sym = external hidden global [0 x i8]
4130
@abs_sym = external hidden global [0 x i8], !absolute_symbol !0
4231
@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
4532

4633
!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
34+
!1 = !{i64 -2147483648, i64 2147483648} ;; In range

0 commit comments

Comments
 (0)