[llvm] [X86] Use 32-bit jump table entries on Windows (PR #95962)

via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 18 11:05:28 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-x86

Author: Arthur Eubanks (aeubanks)

<details>
<summary>Changes</summary>

Windows doesn't support relative 64-bit relocations.

Fixes #<!-- -->95622

---
Full diff: https://github.com/llvm/llvm-project/pull/95962.diff


2 Files Affected:

- (modified) llvm/lib/Target/X86/X86ISelLoweringCall.cpp (+2-1) 
- (modified) llvm/test/CodeGen/X86/win64-jumptable.ll (+10-2) 


``````````diff
diff --git a/llvm/lib/Target/X86/X86ISelLoweringCall.cpp b/llvm/lib/Target/X86/X86ISelLoweringCall.cpp
index b107d56f8cf9b..2d3e20da5065b 100644
--- a/llvm/lib/Target/X86/X86ISelLoweringCall.cpp
+++ b/llvm/lib/Target/X86/X86ISelLoweringCall.cpp
@@ -417,7 +417,8 @@ unsigned X86TargetLowering::getJumpTableEncoding() const {
   if (isPositionIndependent() && Subtarget.isPICStyleGOT())
     return MachineJumpTableInfo::EK_Custom32;
   if (isPositionIndependent() &&
-      getTargetMachine().getCodeModel() == CodeModel::Large)
+      getTargetMachine().getCodeModel() == CodeModel::Large &&
+      !Subtarget.isOSWindows())
     return MachineJumpTableInfo::EK_LabelDifference64;
 
   // Otherwise, use the normal jump table encoding heuristics.
diff --git a/llvm/test/CodeGen/X86/win64-jumptable.ll b/llvm/test/CodeGen/X86/win64-jumptable.ll
index c8db8b63f0e78..17ef0d333a727 100644
--- a/llvm/test/CodeGen/X86/win64-jumptable.ll
+++ b/llvm/test/CodeGen/X86/win64-jumptable.ll
@@ -1,6 +1,8 @@
-; RUN: llc < %s -relocation-model static | FileCheck %s
+; RUN: llc < %s -relocation-model=static | FileCheck %s
+; RUN: llc < %s -relocation-model=pic | FileCheck %s --check-prefix=PIC
+; RUN: llc < %s -relocation-model=pic -code-model=large | FileCheck %s --check-prefix=PIC
 
-; FIXME: Remove '-relocation-model static' when it is no longer necessary to
+; FIXME: Remove '-relocation-model=static' when it is no longer necessary to
 ; trigger the separate .rdata section.
 
 target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
@@ -57,3 +59,9 @@ declare void @g(i32)
 ; It's important that we switch back to .text here, not .rdata.
 ; CHECK: .text
 ; CHECK: .seh_endproc
+
+; Windows PIC code should use 32-bit entries
+; PIC: .long .LBB0_2-.LJTI0_0
+; PIC: .long .LBB0_3-.LJTI0_0
+; PIC: .long .LBB0_4-.LJTI0_0
+; PIC: .long .LBB0_5-.LJTI0_0

``````````

</details>


https://github.com/llvm/llvm-project/pull/95962


More information about the llvm-commits mailing list