[llvm] r358343 - [X86] Use PC-relative mode for the kernel code model
Bill Wendling via llvm-commits
llvm-commits at lists.llvm.org
Sat Apr 13 14:39:29 PDT 2019
Author: void
Date: Sat Apr 13 14:39:28 2019
New Revision: 358343
URL: http://llvm.org/viewvc/llvm-project?rev=358343&view=rev
Log:
[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
Modified:
llvm/trunk/lib/Target/X86/X86ISelDAGToDAG.cpp
llvm/trunk/test/CodeGen/X86/codemodel.ll
llvm/trunk/unittests/Support/VirtualFileSystemTest.cpp
Modified: llvm/trunk/lib/Target/X86/X86ISelDAGToDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelDAGToDAG.cpp?rev=358343&r1=358342&r2=358343&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86ISelDAGToDAG.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86ISelDAGToDAG.cpp Sat Apr 13 14:39:28 2019
@@ -1264,15 +1264,20 @@ bool X86DAGToDAGISel::matchAddress(SDVal
// Post-processing: Convert foo to foo(%rip), even in non-PIC mode,
// because it has a smaller encoding.
// TODO: Which other code models can use this?
- if (TM.getCodeModel() == CodeModel::Small &&
- Subtarget->is64Bit() &&
- AM.Scale == 1 &&
- AM.BaseType == X86ISelAddressMode::RegBase &&
- AM.Base_Reg.getNode() == nullptr &&
- AM.IndexReg.getNode() == nullptr &&
- AM.SymbolFlags == X86II::MO_NO_FLAG &&
- AM.hasSymbolicDisplacement())
- AM.Base_Reg = CurDAG->getRegister(X86::RIP, MVT::i64);
+ switch (TM.getCodeModel()) {
+ default: break;
+ case CodeModel::Small:
+ case CodeModel::Kernel:
+ if (Subtarget->is64Bit() &&
+ AM.Scale == 1 &&
+ AM.BaseType == X86ISelAddressMode::RegBase &&
+ AM.Base_Reg.getNode() == nullptr &&
+ AM.IndexReg.getNode() == nullptr &&
+ AM.SymbolFlags == X86II::MO_NO_FLAG &&
+ AM.hasSymbolicDisplacement())
+ AM.Base_Reg = CurDAG->getRegister(X86::RIP, MVT::i64);
+ break;
+ }
return false;
}
Modified: llvm/trunk/test/CodeGen/X86/codemodel.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/codemodel.ll?rev=358343&r1=358342&r2=358343&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/codemodel.ll (original)
+++ llvm/trunk/test/CodeGen/X86/codemodel.ll Sat Apr 13 14:39:28 2019
@@ -13,17 +13,27 @@ entry:
; CHECK-SMALL-LABEL: foo:
; CHECK-SMALL: movl data(%rip), %eax
; 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]
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 {
entry:
; CHECK-SMALL-LABEL: foo2:
; CHECK-SMALL: movl data+40(%rip), %eax
; 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]
ret i32 %0
}
@@ -34,6 +44,7 @@ entry:
; CHECK-SMALL: movl data-40(%rip), %eax
; CHECK-KERNEL-LABEL: foo3:
; 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]
ret i32 %0
}
@@ -45,26 +56,18 @@ entry:
; CHECK-SMALL: movl $16777216, %eax
; CHECK-SMALL: movl data(%rax), %eax
; 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]
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 {
entry:
; CHECK-SMALL-LABEL: foo5:
; CHECK-SMALL: movl data-16777216(%rip), %eax
; CHECK-KERNEL-LABEL: foo5:
; 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]
ret i32 %0
}
Modified: llvm/trunk/unittests/Support/VirtualFileSystemTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/VirtualFileSystemTest.cpp?rev=358343&r1=358342&r2=358343&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/VirtualFileSystemTest.cpp (original)
+++ llvm/trunk/unittests/Support/VirtualFileSystemTest.cpp Sat Apr 13 14:39:28 2019
@@ -401,8 +401,9 @@ struct ScopedFile {
this->Path = "";
}
~ScopedFile() {
- if (Path != "")
+ if (Path != "") {
EXPECT_FALSE(llvm::sys::fs::remove(Path.str()));
+ }
}
};
} // end anonymous namespace
More information about the llvm-commits
mailing list