[clang] [llvm] [X86][APX] Enable PP2/PPX generation on Windows (PR #202984)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 10 07:04:11 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-x86
@llvm/pr-subscribers-clang-driver
Author: Timur Golubovich (timurgol007)
<details>
<summary>Changes</summary>
Revert restrictions from https://github.com/llvm/llvm-project/pull/178122 which disabled PUSH2/POP2/PPX on Windows due to missing unwinder opcodes. Now that unwinder support has landed, this is no longer needed.
---
Full diff: https://github.com/llvm/llvm-project/pull/202984.diff
8 Files Affected:
- (modified) clang/lib/Basic/Targets/X86.cpp (+3-8)
- (modified) clang/lib/Driver/ToolChains/Arch/X86.cpp (+4-8)
- (modified) clang/test/Driver/cl-x86-flags.c (+2-2)
- (modified) clang/test/Driver/x86-target-features.c (+2-2)
- (modified) llvm/lib/Target/X86/X86Subtarget.cpp (-3)
- (modified) llvm/lib/TargetParser/Host.cpp (-2)
- (modified) llvm/test/CodeGen/X86/apx/push2-pop2-cfi-seh-v3.ll (+1-42)
- (modified) llvm/test/CodeGen/X86/apx/push2-pop2-cfi-seh.ll (+1-1)
``````````diff
diff --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index d61657bbb4210..18036ba109db0 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -164,11 +164,6 @@ bool X86TargetInfo::initFeatureMap(
for (auto &F : CPUFeatures)
setFeatureEnabled(Features, F, true);
- if (Features.lookup("egpr") && getTriple().isOSWindows()) {
- setFeatureEnabled(Features, "push2pop2", false);
- setFeatureEnabled(Features, "ppx", false);
- }
-
std::vector<std::string> UpdatedFeaturesVec;
for (const auto &Feature : FeaturesVec) {
// Expand general-regs-only to -x86, -mmx and -sse
@@ -988,9 +983,9 @@ void X86TargetInfo::getTargetDefines(const LangOptions &Opts,
Builder.defineMacro("__ZU__");
if (HasJMPABS)
Builder.defineMacro("__JMPABS__");
- if (HasEGPR && HasNDD && HasCCMP && HasNF && HasZU && HasJMPABS)
- if (getTriple().isOSWindows() || (HasPush2Pop2 && HasPPX))
- Builder.defineMacro("__APX_F__");
+ if (HasEGPR && HasPush2Pop2 && HasPPX && HasNDD && HasCCMP && HasNF &&
+ HasZU && HasJMPABS)
+ Builder.defineMacro("__APX_F__");
if (HasEGPR && HasInlineAsmUseGPR32)
Builder.defineMacro("__APX_INLINE_ASM_USE_GPR32__");
diff --git a/clang/lib/Driver/ToolChains/Arch/X86.cpp b/clang/lib/Driver/ToolChains/Arch/X86.cpp
index daab744b2caaa..edcba18f50be8 100644
--- a/clang/lib/Driver/ToolChains/Arch/X86.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/X86.cpp
@@ -264,16 +264,12 @@ void x86::getX86TargetFeatures(const Driver &D, const llvm::Triple &Triple,
A->getOption().matches(options::OPT_mno_apxf)) {
if (IsNegative) {
EGPROpt = EGPRFeature::Disabled;
- Features.insert(Features.end(),
- {"-egpr", "-ndd", "-ccmp", "-nf", "-zu", "-jmpabs"});
- if (!Triple.isOSWindows())
- Features.insert(Features.end(), {"-push2pop2", "-ppx"});
+ Features.insert(Features.end(), {"-egpr", "-push2pop2", "-ppx", "-ndd",
+ "-ccmp", "-nf", "-zu", "-jmpabs"});
} else {
EGPROpt = EGPRFeature::Enabled;
- Features.insert(Features.end(),
- {"+egpr", "+ndd", "+ccmp", "+nf", "+zu", "+jmpabs"});
- if (!Triple.isOSWindows())
- Features.insert(Features.end(), {"+push2pop2", "+ppx"});
+ Features.insert(Features.end(), {"+egpr", "+push2pop2", "+ppx", "+ndd",
+ "+ccmp", "+nf", "+zu", "+jmpabs"});
if (Not64Bit)
D.Diag(diag::err_drv_unsupported_opt_for_target)
diff --git a/clang/test/Driver/cl-x86-flags.c b/clang/test/Driver/cl-x86-flags.c
index d0066b376a512..5073b7b2bfbb6 100644
--- a/clang/test/Driver/cl-x86-flags.c
+++ b/clang/test/Driver/cl-x86-flags.c
@@ -225,6 +225,6 @@ void f(void) {
// RUN: %clang_cl --target=x86_64-pc-windows -mapxf -### -- 2>&1 %s | FileCheck -check-prefix=APXF %s
// RUN: %clang_cl --target=x86_64-pc-windows -mapxf -mno-apxf -### -- 2>&1 %s | FileCheck -check-prefix=NO-APXF %s
// RUN: %clang_cl --target=x86_64-pc-windows -mapx-features=egpr,push2pop2,ppx,ndd,ccmp,nf,cf,zu,jmpabs -### -- 2>&1 %s | FileCheck -check-prefix=APXALL %s
-// APXF: "-target-feature" "+egpr" "-target-feature" "+ndd" "-target-feature" "+ccmp" "-target-feature" "+nf" "-target-feature" "+zu" "-target-feature" "+jmpabs"
-// NO-APXF: "-target-feature" "-egpr" "-target-feature" "-ndd" "-target-feature" "-ccmp" "-target-feature" "-nf" "-target-feature" "-zu" "-target-feature" "-jmpabs"
+// APXF: "-target-feature" "+egpr" "-target-feature" "+push2pop2" "-target-feature" "+ppx" "-target-feature" "+ndd" "-target-feature" "+ccmp" "-target-feature" "+nf" "-target-feature" "+zu" "-target-feature" "+jmpabs"
+// NO-APXF: "-target-feature" "-egpr" "-target-feature" "-push2pop2" "-target-feature" "-ppx" "-target-feature" "-ndd" "-target-feature" "-ccmp" "-target-feature" "-nf" "-target-feature" "-zu" "-target-feature" "-jmpabs"
// APXALL: "-target-feature" "+egpr" "-target-feature" "+push2pop2" "-target-feature" "+ppx" "-target-feature" "+ndd" "-target-feature" "+ccmp" "-target-feature" "+nf" "-target-feature" "+cf" "-target-feature" "+zu" "-target-feature" "+jmpabs"
diff --git a/clang/test/Driver/x86-target-features.c b/clang/test/Driver/x86-target-features.c
index b6ca38c92003f..154379ef73072 100644
--- a/clang/test/Driver/x86-target-features.c
+++ b/clang/test/Driver/x86-target-features.c
@@ -444,8 +444,8 @@
// RUN: %clang --target=x86_64-unknown-linux-gnu -mno-apxf -mapxf %s -### -o %t.o 2>&1 | FileCheck -check-prefix=APXF %s
// RUN: %clang --target=x86_64-unknown-linux-gnu -mapxf -mno-apxf %s -### -o %t.o 2>&1 | FileCheck -check-prefix=NO-APXF %s
//
-// APXF: "-target-feature" "+egpr" "-target-feature" "+ndd" "-target-feature" "+ccmp" "-target-feature" "+nf" "-target-feature" "+zu" "-target-feature" "+jmpabs" "-target-feature" "+push2pop2" "-target-feature" "+ppx"
-// NO-APXF: "-target-feature" "-egpr" "-target-feature" "-ndd" "-target-feature" "-ccmp" "-target-feature" "-nf" "-target-feature" "-zu" "-target-feature" "-jmpabs" "-target-feature" "-push2pop2" "-target-feature" "-ppx"
+// APXF: "-target-feature" "+egpr" "-target-feature" "+push2pop2" "-target-feature" "+ppx" "-target-feature" "+ndd" "-target-feature" "+ccmp" "-target-feature" "+nf" "-target-feature" "+zu" "-target-feature" "+jmpabs"
+// NO-APXF: "-target-feature" "-egpr" "-target-feature" "-push2pop2" "-target-feature" "-ppx" "-target-feature" "-ndd" "-target-feature" "-ccmp" "-target-feature" "-nf" "-target-feature" "-zu" "-target-feature" "-jmpabs"
// RUN: %clang --target=x86_64-unknown-linux-gnu -mapx-features=egpr %s -### -o %t.o 2>&1 | FileCheck -check-prefix=EGPR %s
// RUN: %clang --target=x86_64-unknown-linux-gnu -mapx-features=push2pop2 %s -### -o %t.o 2>&1 | FileCheck -check-prefix=PUSH2POP2 %s
diff --git a/llvm/lib/Target/X86/X86Subtarget.cpp b/llvm/lib/Target/X86/X86Subtarget.cpp
index c576ba9e45506..7b8437005a031 100644
--- a/llvm/lib/Target/X86/X86Subtarget.cpp
+++ b/llvm/lib/Target/X86/X86Subtarget.cpp
@@ -257,9 +257,6 @@ void X86Subtarget::initSubtargetFeatures(StringRef CPU, StringRef TuneCPU,
std::string FullFS = X86_MC::ParseX86Triple(TargetTriple);
assert(!FullFS.empty() && "Failed to parse X86 triple");
- if (TargetTriple.isOSWindows())
- FullFS += ",-push2pop2,-ppx";
-
if (!FS.empty())
FullFS = (Twine(FullFS) + "," + FS).str();
diff --git a/llvm/lib/TargetParser/Host.cpp b/llvm/lib/TargetParser/Host.cpp
index 881c963585e75..34f4b17a3855e 100644
--- a/llvm/lib/TargetParser/Host.cpp
+++ b/llvm/lib/TargetParser/Host.cpp
@@ -2214,12 +2214,10 @@ StringMap<bool> sys::getHostCPUFeatures() {
bool HasAVX10 = HasLeaf7Subleaf1 && ((EDX >> 19) & 1);
bool HasAPXF = HasLeaf7Subleaf1 && ((EDX >> 21) & 1) && HasAPXSave;
Features["egpr"] = HasAPXF;
-#ifndef _WIN32
// TODO: We may need to check OS or MSVC version once unwinder opcodes
// support PUSH2/POP2/PPX.
Features["push2pop2"] = HasAPXF;
Features["ppx"] = HasAPXF;
-#endif
Features["ndd"] = HasAPXF;
Features["ccmp"] = HasAPXF;
Features["nf"] = HasAPXF;
diff --git a/llvm/test/CodeGen/X86/apx/push2-pop2-cfi-seh-v3.ll b/llvm/test/CodeGen/X86/apx/push2-pop2-cfi-seh-v3.ll
index 7f3df90123de2..671146a8daea4 100644
--- a/llvm/test/CodeGen/X86/apx/push2-pop2-cfi-seh-v3.ll
+++ b/llvm/test/CodeGen/X86/apx/push2-pop2-cfi-seh-v3.ll
@@ -2,7 +2,7 @@
; RUN: llc < %s -mtriple=x86_64-windows-msvc | FileCheck %s --check-prefix=WIN-V3-REF
; RUN: llc < %s -mtriple=x86_64-windows-msvc -mattr=+push2pop2 | FileCheck %s --check-prefix=WIN-V3
; RUN: llc < %s -mtriple=x86_64-windows-msvc -mattr=+push2pop2,+ppx | FileCheck %s --check-prefix=WIN-V3-PPX
-; RUN: llc < %s -mtriple=x86_64-windows-msvc -mcpu=diamondrapids | FileCheck %s --check-prefix=WIN-V3-DR
+; RUN: llc < %s -mtriple=x86_64-windows-msvc -mcpu=diamondrapids | FileCheck %s --check-prefix=WIN-V3-PPX
; V3 unwind info is enabled module-wide here. diamondrapids (which enables
; EGPR) requires V3, but with V3 enabled the SEH prolog/epilogue ordering
@@ -115,47 +115,6 @@ define i32 @csr6_alloc16(ptr %argv) {
; WIN-V3-PPX-NEXT: .seh_endepilogue
; WIN-V3-PPX-NEXT: retq
; WIN-V3-PPX-NEXT: .seh_endproc
-;
-; WIN-V3-DR-LABEL: csr6_alloc16:
-; WIN-V3-DR: # %bb.0: # %entry
-; WIN-V3-DR-NEXT: .seh_pushreg %r15
-; WIN-V3-DR-NEXT: pushq %r15
-; WIN-V3-DR-NEXT: .seh_pushreg %r14
-; WIN-V3-DR-NEXT: pushq %r14
-; WIN-V3-DR-NEXT: .seh_pushreg %r13
-; WIN-V3-DR-NEXT: pushq %r13
-; WIN-V3-DR-NEXT: .seh_pushreg %r12
-; WIN-V3-DR-NEXT: pushq %r12
-; WIN-V3-DR-NEXT: .seh_pushreg %rbp
-; WIN-V3-DR-NEXT: pushq %rbp
-; WIN-V3-DR-NEXT: .seh_pushreg %rbx
-; WIN-V3-DR-NEXT: pushq %rbx
-; WIN-V3-DR-NEXT: .seh_stackalloc 56
-; WIN-V3-DR-NEXT: subq $56, %rsp
-; WIN-V3-DR-NEXT: .seh_endprologue
-; WIN-V3-DR-NEXT: #APP
-; WIN-V3-DR-NEXT: #NO_APP
-; WIN-V3-DR-NEXT: xorl %eax, %eax
-; WIN-V3-DR-NEXT: callq *%rax
-; WIN-V3-DR-NEXT: nop
-; WIN-V3-DR-NEXT: .seh_startepilogue
-; WIN-V3-DR-NEXT: .seh_stackalloc 56
-; WIN-V3-DR-NEXT: addq $56, %rsp
-; WIN-V3-DR-NEXT: .seh_pushreg %rbx
-; WIN-V3-DR-NEXT: popq %rbx
-; WIN-V3-DR-NEXT: .seh_pushreg %rbp
-; WIN-V3-DR-NEXT: popq %rbp
-; WIN-V3-DR-NEXT: .seh_pushreg %r12
-; WIN-V3-DR-NEXT: popq %r12
-; WIN-V3-DR-NEXT: .seh_pushreg %r13
-; WIN-V3-DR-NEXT: popq %r13
-; WIN-V3-DR-NEXT: .seh_pushreg %r14
-; WIN-V3-DR-NEXT: popq %r14
-; WIN-V3-DR-NEXT: .seh_pushreg %r15
-; WIN-V3-DR-NEXT: popq %r15
-; WIN-V3-DR-NEXT: .seh_endepilogue
-; WIN-V3-DR-NEXT: retq
-; WIN-V3-DR-NEXT: .seh_endproc
entry:
tail call void asm sideeffect "", "~{rbp},~{r15},~{r14},~{r13},~{r12},~{rbx},~{dirflag},~{fpsr},~{flags}"()
%a = alloca [3 x ptr], align 8
diff --git a/llvm/test/CodeGen/X86/apx/push2-pop2-cfi-seh.ll b/llvm/test/CodeGen/X86/apx/push2-pop2-cfi-seh.ll
index bd81d36f2db0f..aabaa968a11b9 100644
--- a/llvm/test/CodeGen/X86/apx/push2-pop2-cfi-seh.ll
+++ b/llvm/test/CodeGen/X86/apx/push2-pop2-cfi-seh.ll
@@ -10,7 +10,7 @@
; EPGR normally required unwind v3 info, but that changes the SEH directives
; that get emitted, so disable epgr so that we can validate diamondrapids
; enables push2pop2
-; RUN: llc < %s -mtriple=x86_64-windows-msvc -mcpu=diamondrapids -mattr=-egpr | FileCheck %s --check-prefix=WIN-REF
+; RUN: llc < %s -mtriple=x86_64-windows-msvc -mcpu=diamondrapids -mattr=-egpr | FileCheck %s --check-prefix=WIN-PPX
define i32 @csr6_alloc16(ptr %argv) {
; LIN-REF-LABEL: csr6_alloc16:
``````````
</details>
https://github.com/llvm/llvm-project/pull/202984
More information about the cfe-commits
mailing list