[X86] Use PC-relative mode for the kernel code model

Summary:
The Linux kernel uses PC-relative mode, so allow that when the code model is
"kernel".

Reviewers: craig.topper

Reviewed By: craig.topper

Subscribers: llvm-commits, kees, nickdesaulniers

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D60643

llvm-svn: 358343
This commit is contained in:
Bill Wendling 2019-04-13 21:39:28 +00:00
parent 040871db48
commit 191f1487b6
3 changed files with 31 additions and 22 deletions

View File

@ -1264,8 +1264,11 @@ bool X86DAGToDAGISel::matchAddress(SDValue N, X86ISelAddressMode &AM) {
// Post-processing: Convert foo to foo(%rip), even in non-PIC mode, // Post-processing: Convert foo to foo(%rip), even in non-PIC mode,
// because it has a smaller encoding. // because it has a smaller encoding.
// TODO: Which other code models can use this? // TODO: Which other code models can use this?
if (TM.getCodeModel() == CodeModel::Small && switch (TM.getCodeModel()) {
Subtarget->is64Bit() && default: break;
case CodeModel::Small:
case CodeModel::Kernel:
if (Subtarget->is64Bit() &&
AM.Scale == 1 && AM.Scale == 1 &&
AM.BaseType == X86ISelAddressMode::RegBase && AM.BaseType == X86ISelAddressMode::RegBase &&
AM.Base_Reg.getNode() == nullptr && AM.Base_Reg.getNode() == nullptr &&
@ -1273,6 +1276,8 @@ bool X86DAGToDAGISel::matchAddress(SDValue N, X86ISelAddressMode &AM) {
AM.SymbolFlags == X86II::MO_NO_FLAG && AM.SymbolFlags == X86II::MO_NO_FLAG &&
AM.hasSymbolicDisplacement()) AM.hasSymbolicDisplacement())
AM.Base_Reg = CurDAG->getRegister(X86::RIP, MVT::i64); AM.Base_Reg = CurDAG->getRegister(X86::RIP, MVT::i64);
break;
}
return false; return false;
} }

View File

@ -13,17 +13,27 @@ entry:
; CHECK-SMALL-LABEL: foo: ; CHECK-SMALL-LABEL: foo:
; CHECK-SMALL: movl data(%rip), %eax ; CHECK-SMALL: movl data(%rip), %eax
; CHECK-KERNEL-LABEL: foo: ; CHECK-KERNEL-LABEL: foo:
; CHECK-KERNEL: movl data, %eax ; CHECK-KERNEL: movl data(%rip), %eax
%0 = load i32, i32* getelementptr ([0 x i32], [0 x i32]* @data, i64 0, i64 0), align 4 ; <i32> [#uses=1] %0 = load i32, i32* getelementptr ([0 x i32], [0 x i32]* @data, i64 0, i64 0), align 4 ; <i32> [#uses=1]
ret i32 %0 ret i32 %0
} }
define i32 @foo1() nounwind readonly {
entry:
; CHECK-SMALL-LABEL: foo1:
; CHECK-SMALL: movl data+16777212(%rip), %eax
; CHECK-KERNEL-LABEL: foo1:
; CHECK-KERNEL: movl data+16777212(%rip), %eax
%0 = load i32, i32* getelementptr ([0 x i32], [0 x i32]* @data, i32 0, i64 4194303), align 4 ; <i32> [#uses=1]
ret i32 %0
}
define i32 @foo2() nounwind readonly { define i32 @foo2() nounwind readonly {
entry: entry:
; CHECK-SMALL-LABEL: foo2: ; CHECK-SMALL-LABEL: foo2:
; CHECK-SMALL: movl data+40(%rip), %eax ; CHECK-SMALL: movl data+40(%rip), %eax
; CHECK-KERNEL-LABEL: foo2: ; CHECK-KERNEL-LABEL: foo2:
; CHECK-KERNEL: movl data+40, %eax ; CHECK-KERNEL: movl data+40(%rip), %eax
%0 = load i32, i32* getelementptr ([0 x i32], [0 x i32]* @data, i32 0, i64 10), align 4 ; <i32> [#uses=1] %0 = load i32, i32* getelementptr ([0 x i32], [0 x i32]* @data, i32 0, i64 10), align 4 ; <i32> [#uses=1]
ret i32 %0 ret i32 %0
} }
@ -34,6 +44,7 @@ entry:
; CHECK-SMALL: movl data-40(%rip), %eax ; CHECK-SMALL: movl data-40(%rip), %eax
; CHECK-KERNEL-LABEL: foo3: ; CHECK-KERNEL-LABEL: foo3:
; CHECK-KERNEL: movq $-40, %rax ; CHECK-KERNEL: movq $-40, %rax
; CHECK-KERNEL: movl data(%rax), %eax
%0 = load i32, i32* getelementptr ([0 x i32], [0 x i32]* @data, i32 0, i64 -10), align 4 ; <i32> [#uses=1] %0 = load i32, i32* getelementptr ([0 x i32], [0 x i32]* @data, i32 0, i64 -10), align 4 ; <i32> [#uses=1]
ret i32 %0 ret i32 %0
} }
@ -45,26 +56,18 @@ entry:
; CHECK-SMALL: movl $16777216, %eax ; CHECK-SMALL: movl $16777216, %eax
; CHECK-SMALL: movl data(%rax), %eax ; CHECK-SMALL: movl data(%rax), %eax
; CHECK-KERNEL-LABEL: foo4: ; CHECK-KERNEL-LABEL: foo4:
; CHECK-KERNEL: movl data+16777216, %eax ; CHECK-KERNEL: movl data+16777216(%rip), %eax
%0 = load i32, i32* getelementptr ([0 x i32], [0 x i32]* @data, i32 0, i64 4194304), align 4 ; <i32> [#uses=1] %0 = load i32, i32* getelementptr ([0 x i32], [0 x i32]* @data, i32 0, i64 4194304), align 4 ; <i32> [#uses=1]
ret i32 %0 ret i32 %0
} }
define i32 @foo1() nounwind readonly {
entry:
; CHECK-SMALL-LABEL: foo1:
; CHECK-SMALL: movl data+16777212(%rip), %eax
; CHECK-KERNEL-LABEL: foo1:
; CHECK-KERNEL: movl data+16777212, %eax
%0 = load i32, i32* getelementptr ([0 x i32], [0 x i32]* @data, i32 0, i64 4194303), align 4 ; <i32> [#uses=1]
ret i32 %0
}
define i32 @foo5() nounwind readonly { define i32 @foo5() nounwind readonly {
entry: entry:
; CHECK-SMALL-LABEL: foo5: ; CHECK-SMALL-LABEL: foo5:
; CHECK-SMALL: movl data-16777216(%rip), %eax ; CHECK-SMALL: movl data-16777216(%rip), %eax
; CHECK-KERNEL-LABEL: foo5: ; CHECK-KERNEL-LABEL: foo5:
; CHECK-KERNEL: movq $-16777216, %rax ; CHECK-KERNEL: movq $-16777216, %rax
; CHECK-KERNEL: movl data(%rax), %eax
%0 = load i32, i32* getelementptr ([0 x i32], [0 x i32]* @data, i32 0, i64 -4194304), align 4 ; <i32> [#uses=1] %0 = load i32, i32* getelementptr ([0 x i32], [0 x i32]* @data, i32 0, i64 -4194304), align 4 ; <i32> [#uses=1]
ret i32 %0 ret i32 %0
} }

View File

@ -401,9 +401,10 @@ struct ScopedFile {
this->Path = ""; this->Path = "";
} }
~ScopedFile() { ~ScopedFile() {
if (Path != "") if (Path != "") {
EXPECT_FALSE(llvm::sys::fs::remove(Path.str())); EXPECT_FALSE(llvm::sys::fs::remove(Path.str()));
} }
}
}; };
} // end anonymous namespace } // end anonymous namespace