forked from OSchip/llvm-project
[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:
parent
040871db48
commit
191f1487b6
|
@ -1264,15 +1264,20 @@ 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;
|
||||||
AM.Scale == 1 &&
|
case CodeModel::Small:
|
||||||
AM.BaseType == X86ISelAddressMode::RegBase &&
|
case CodeModel::Kernel:
|
||||||
AM.Base_Reg.getNode() == nullptr &&
|
if (Subtarget->is64Bit() &&
|
||||||
AM.IndexReg.getNode() == nullptr &&
|
AM.Scale == 1 &&
|
||||||
AM.SymbolFlags == X86II::MO_NO_FLAG &&
|
AM.BaseType == X86ISelAddressMode::RegBase &&
|
||||||
AM.hasSymbolicDisplacement())
|
AM.Base_Reg.getNode() == nullptr &&
|
||||||
AM.Base_Reg = CurDAG->getRegister(X86::RIP, MVT::i64);
|
AM.IndexReg.getNode() == nullptr &&
|
||||||
|
AM.SymbolFlags == X86II::MO_NO_FLAG &&
|
||||||
|
AM.hasSymbolicDisplacement())
|
||||||
|
AM.Base_Reg = CurDAG->getRegister(X86::RIP, MVT::i64);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
|
@ -401,8 +401,9 @@ 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
|
||||||
|
|
Loading…
Reference in New Issue