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

via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 18 14:15:16 PDT 2024


Author: Arthur Eubanks
Date: 2024-06-18T14:15:13-07:00
New Revision: 300c41c2bd5a5a5b5c98c603f64a36d2e4df967f

URL: https://github.com/llvm/llvm-project/commit/300c41c2bd5a5a5b5c98c603f64a36d2e4df967f
DIFF: https://github.com/llvm/llvm-project/commit/300c41c2bd5a5a5b5c98c603f64a36d2e4df967f.diff

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

Windows doesn't support relative 64-bit relocations.

Fixes #95622

Added: 
    

Modified: 
    llvm/lib/Target/X86/X86ISelLoweringCall.cpp
    llvm/test/CodeGen/X86/win64-jumptable.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/X86/X86ISelLoweringCall.cpp b/llvm/lib/Target/X86/X86ISelLoweringCall.cpp
index b107d56f8cf9b..8be64b6fff3fc 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.isTargetCOFF())
     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


        


More information about the llvm-commits mailing list