[llvm] d602e79 - [X86] Encode global address in small code model
Wei Wang via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 26 23:14:26 PDT 2020
Author: Wei Wang
Date: 2020-10-26T23:14:06-07:00
New Revision: d602e79a81adceca3ecc0259d6eda305fe9c86c0
URL: https://github.com/llvm/llvm-project/commit/d602e79a81adceca3ecc0259d6eda305fe9c86c0
DIFF: https://github.com/llvm/llvm-project/commit/d602e79a81adceca3ecc0259d6eda305fe9c86c0.diff
LOG: [X86] Encode global address in small code model
In small code model, program and its symbols are linked in the lower 2 GB of
the address space. Try encoding global address even when the range is unknown
in such case.
Differential Revision: https://reviews.llvm.org/D89341
Added:
llvm/test/CodeGen/X86/relocimm-small-model.ll
Modified:
llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
llvm/test/CodeGen/X86/br-fold.ll
llvm/test/CodeGen/X86/critical-edge-split-2.ll
llvm/test/CodeGen/X86/pr33290.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp b/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
index 3791ed5303a6..97c06151dfa9 100644
--- a/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
+++ b/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
@@ -2729,7 +2729,10 @@ bool X86DAGToDAGISel::isSExtAbsoluteSymbolRef(unsigned Width, SDNode *N) const {
return false;
Optional<ConstantRange> CR = GA->getGlobal()->getAbsoluteSymbolRange();
- return CR && CR->getSignedMin().sge(-1ull << Width) &&
+ if (!CR)
+ return Width == 32 && TM.getCodeModel() == CodeModel::Small;
+
+ return CR->getSignedMin().sge(-1ull << Width) &&
CR->getSignedMax().slt(1ull << Width);
}
@@ -3123,7 +3126,7 @@ bool X86DAGToDAGISel::foldLoadStoreIntoMemOperand(SDNode *Node) {
bool IsNegOne = isAllOnesConstant(StoredVal.getOperand(1));
// ADD/SUB with 1/-1 and carry flag isn't used can use inc/dec.
if ((IsOne || IsNegOne) && hasNoCarryFlagUses(StoredVal.getValue(1))) {
- unsigned NewOpc =
+ unsigned NewOpc =
((Opc == X86ISD::ADD) == IsOne)
? SelectOpcode(X86::INC64m, X86::INC32m, X86::INC16m, X86::INC8m)
: SelectOpcode(X86::DEC64m, X86::DEC32m, X86::DEC16m, X86::DEC8m);
diff --git a/llvm/test/CodeGen/X86/br-fold.ll b/llvm/test/CodeGen/X86/br-fold.ll
index 6cd9b78c1c7e..11f5f720a431 100644
--- a/llvm/test/CodeGen/X86/br-fold.ll
+++ b/llvm/test/CodeGen/X86/br-fold.ll
@@ -7,7 +7,7 @@
; X64_DARWIN: orq
; X64_DARWIN-NEXT: ud2
-; X64_LINUX: orq %rax, %rcx
+; X64_LINUX: orq $_ZN11xercesc_2_56XMLUni16fgNotationStringE, %rax
; X64_LINUX-NEXT: jne
; X64_LINUX-NEXT: %bb8.i329
@@ -18,7 +18,7 @@
; X64_WINDOWS_GNU: orq .refptr._ZN11xercesc_2_56XMLUni16fgNotationStringE(%rip), %rax
; X64_WINDOWS_GNU-NEXT: jne
-; PS4: orq %rax, %rcx
+; PS4: orq $_ZN11xercesc_2_56XMLUni16fgNotationStringE, %rax
; PS4-NEXT: ud2
@_ZN11xercesc_2_513SchemaSymbols21fgURI_SCHEMAFORSCHEMAE = external constant [33 x i16], align 32 ; <[33 x i16]*> [#uses=1]
diff --git a/llvm/test/CodeGen/X86/critical-edge-split-2.ll b/llvm/test/CodeGen/X86/critical-edge-split-2.ll
index 1371f847a2bb..2eebed65f735 100644
--- a/llvm/test/CodeGen/X86/critical-edge-split-2.ll
+++ b/llvm/test/CodeGen/X86/critical-edge-split-2.ll
@@ -15,18 +15,18 @@ define i16 @test1(i1 zeroext %C, i8** nocapture %argv) nounwind ssp {
; CHECK-NEXT: testl %edi, %edi
; CHECK-NEXT: jne .LBB0_2
; CHECK-NEXT: # %bb.1: # %cond.false.i
-; CHECK-NEXT: movl $g_4, %eax
-; CHECK-NEXT: movl $g_2+4, %ecx
-; CHECK-NEXT: xorl %esi, %esi
-; CHECK-NEXT: cmpq %rax, %rcx
-; CHECK-NEXT: sete %sil
+; CHECK-NEXT: movl $g_2+4, %eax
+; CHECK-NEXT: xorl %ecx, %ecx
+; CHECK-NEXT: cmpq $g_4, %rax
+; CHECK-NEXT: sete %cl
; CHECK-NEXT: movl $1, %eax
; CHECK-NEXT: xorl %edx, %edx
-; CHECK-NEXT: divl %esi
+; CHECK-NEXT: divl %ecx
; CHECK-NEXT: movl %edx, %eax
; CHECK-NEXT: .LBB0_2: # %cond.end.i
; CHECK-NEXT: # kill: def $ax killed $ax killed $eax
; CHECK-NEXT: retq
+
entry:
br i1 %C, label %cond.end.i, label %cond.false.i
diff --git a/llvm/test/CodeGen/X86/pr33290.ll b/llvm/test/CodeGen/X86/pr33290.ll
index 44b7dca0ae2f..28ac4d43c3ee 100644
--- a/llvm/test/CodeGen/X86/pr33290.ll
+++ b/llvm/test/CodeGen/X86/pr33290.ll
@@ -22,17 +22,16 @@ define void @e() {
; X64-LABEL: e:
; X64: # %bb.0: # %entry
; X64-NEXT: movq {{.*}}(%rip), %rax
-; X64-NEXT: movl $a, %esi
; X64-NEXT: .p2align 4, 0x90
; X64-NEXT: .LBB0_1: # %for.cond
; X64-NEXT: # =>This Inner Loop Header: Depth=1
-; X64-NEXT: movzbl {{.*}}(%rip), %edx
-; X64-NEXT: addq %rsi, %rdx
-; X64-NEXT: setb %cl
-; X64-NEXT: addq $2, %rdx
-; X64-NEXT: adcb $0, %cl
-; X64-NEXT: movb %cl, {{.*}}(%rip)
-; X64-NEXT: movl %edx, (%rax)
+; X64-NEXT: movzbl {{.*}}(%rip), %ecx
+; X64-NEXT: addq $a, %rcx
+; X64-NEXT: setb %dl
+; X64-NEXT: addq $2, %rcx
+; X64-NEXT: adcb $0, %dl
+; X64-NEXT: movb %dl, {{.*}}(%rip)
+; X64-NEXT: movl %ecx, (%rax)
; X64-NEXT: jmp .LBB0_1
entry:
%0 = load i32*, i32** @b, align 8
diff --git a/llvm/test/CodeGen/X86/relocimm-small-model.ll b/llvm/test/CodeGen/X86/relocimm-small-model.ll
new file mode 100644
index 000000000000..f3e92b27d838
--- /dev/null
+++ b/llvm/test/CodeGen/X86/relocimm-small-model.ll
@@ -0,0 +1,25 @@
+; RUN: llc < %s | FileCheck %s --check-prefix=CHECK-SMALL
+; RUN: llc --code-model=medium < %s | FileCheck %s --check-prefix=CHECK-MEDIUM
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+ at a = external dso_local global i32, align 4
+
+declare void @f()
+
+define void @foo(i64 %b) {
+; CHECK-MEDIUM: cmpq %rax, %rdi
+; CHECK-SMALL: cmpq $a, %rdi
+entry:
+ %cmp = icmp eq i64 %b, ptrtoint (i32* @a to i64)
+ br i1 %cmp, label %if.then, label %if.end
+
+if.then: ; preds = %entry
+ tail call void @f()
+ br label %if.end
+
+if.end: ; preds = %if.then, %entry
+ ret void
+}
+
More information about the llvm-commits
mailing list