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

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 18 11:04:58 PDT 2024


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

Windows doesn't support relative 64-bit relocations.

Fixes #95622

>From 24b7f3db9f9744008000db879e8e8be6bf92e0b5 Mon Sep 17 00:00:00 2001
From: Arthur Eubanks <aeubanks at google.com>
Date: Tue, 18 Jun 2024 18:01:51 +0000
Subject: [PATCH] [X86] Use 32-bit jump table entries on Windows

Windows doesn't support relative 64-bit relocations.

Fixes #95622
---
 llvm/lib/Target/X86/X86ISelLoweringCall.cpp |  3 ++-
 llvm/test/CodeGen/X86/win64-jumptable.ll    | 12 ++++++++++--
 2 files changed, 12 insertions(+), 3 deletions(-)

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



More information about the llvm-commits mailing list