]> granicus.if.org Git - llvm/commitdiff
[X86] Use PC-relative mode for the kernel code model
authorBill Wendling <isanbard@gmail.com>
Sat, 13 Apr 2019 21:39:28 +0000 (21:39 +0000)
committerBill Wendling <isanbard@gmail.com>
Sat, 13 Apr 2019 21:39:28 +0000 (21:39 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358343 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/X86/X86ISelDAGToDAG.cpp
test/CodeGen/X86/codemodel.ll
unittests/Support/VirtualFileSystemTest.cpp

index 52b0f7e88cac1403f48768838ba110cf33beedf3..cce4d9bb3825c288bf30a86b2d99e54901a86b0e 100644 (file)
@@ -1264,15 +1264,20 @@ bool X86DAGToDAGISel::matchAddress(SDValue N, X86ISelAddressMode &AM) {
   // 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;
 }
index 8febb3f0b0a5dc29de8ee7de4f45b06533ac5c60..d7ed7c460889e40aa30bbcadcbf9b63c8e97e22b 100644 (file)
@@ -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
 }
index 9c0b5045116bdd75fa986b70608fb323f6399265..55cb597cc430539419054ab9fd3ab4cf43bf7aa9 100644 (file)
@@ -401,8 +401,9 @@ struct ScopedFile {
       this->Path = "";
   }
   ~ScopedFile() {
-    if (Path != "")
+    if (Path != "") {
       EXPECT_FALSE(llvm::sys::fs::remove(Path.str()));
+    }
   }
 };
 } // end anonymous namespace