[flang-commits] [clang] [flang] [flang] Add driver support for x86 -m[option] target feature flags (PR #220159)

via flang-commits flang-commits at lists.llvm.org
Mon Aug 31 23:12:01 PDT 2026


https://github.com/shivaramaarao created https://github.com/llvm/llvm-project/pull/220159

Added FlangOption visibility to m_x86_Features_Group so flags such as -mavx, -mavx2, and -mavx512f are accepted by flang and forwarded as -target-feature to -fc1 via the shared Clang driver logic.

Also extended target-cpu-features.f90 with grouped driver tests that cover m_x86_Features_Group options, including representative -mno-*, APX cases

Assisted by : Cursor (testcase generation)

>From a235c789706f2c52d1a186750931ced38c09e1bd Mon Sep 17 00:00:00 2001
From: Shivarama Rao <shivarama.rao at amd.com>
Date: Tue, 1 Sep 2026 11:33:18 +0530
Subject: [PATCH] [flang] Add driver support for x86 -m* target feature flags

Added FlangOption visibility to m_x86_Features_Group so flags such as -mavx,
-mavx2, and -mavx512f are accepted by flang and forwarded as -target-feature
to -fc1 via the shared Clang driver logic.

Also extended target-cpu-features.f90 with grouped driver tests that cover
m_x86_Features_Group options, including representative -mno-*, APX cases

Assisted by : Cursor (testcase generation)
---
 clang/include/clang/Options/Options.td    |   3 +-
 flang/test/Driver/target-cpu-features.f90 | 170 ++++++++++++++++++++--
 2 files changed, 160 insertions(+), 13 deletions(-)

diff --git a/clang/include/clang/Options/Options.td b/clang/include/clang/Options/Options.td
index eb5a009b5628c..3c1829a70d976 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -235,7 +235,8 @@ def m_wasm_Features_Group : OptionGroup<"<wasm features group>">,
 def m_wasm_Features_Driver_Group : OptionGroup<"<wasm driver features group>">,
                                    Group<m_Group>, DocName<"WebAssembly Driver">;
 def m_x86_Features_Group : OptionGroup<"<x86 features group>">,
-                           Group<m_Group>, Visibility<[ClangOption, CLOption]>,
+                           Group<m_Group>,
+                           Visibility<[ClangOption, CLOption, FlangOption]>,
                            DocName<"X86">;
 def m_x86_AVX10_Features_Group : OptionGroup<"<x86 AVX10 features group>">,
                                  Group<m_Group>, Visibility<[ClangOption, CLOption]>,
diff --git a/flang/test/Driver/target-cpu-features.f90 b/flang/test/Driver/target-cpu-features.f90
index 97175b767e329..3dd98386c0aa8 100644
--- a/flang/test/Driver/target-cpu-features.f90
+++ b/flang/test/Driver/target-cpu-features.f90
@@ -1,5 +1,8 @@
 ! Test that -mcpu/march are used and that the -target-cpu and -target-features
 ! are also added to the fc1 command.
+!
+! The X86 section uses grouped RUN lines to verify m_x86_Features_Group options
+! are accepted and forwarded as -target-feature to flang -fc1.
 
 ! RUN: %flang --target=aarch64-linux-gnu -mcpu=cortex-a57 -c %s -### 2>&1 \
 ! RUN: | FileCheck %s -check-prefix=CHECK-A57
@@ -17,12 +20,6 @@
 ! RUN: %flang --target=x86_64-linux-gnu -march=skylake -c %s -### 2>&1 \
 ! RUN: | FileCheck %s -check-prefix=CHECK-SKYLAKE
 
-! RUN: %flang --target=x86_64-linux-gnu -mapx-features=egpr -c %s -### 2>&1 \
-! RUN: | FileCheck %s -check-prefix=CHECK-APX
-
-! RUN: %flang --target=x86_64-linux-gnu -mno-apx-features=ccmp -c %s -### 2>&1 \
-! RUN: | FileCheck %s -check-prefix=CHECK-NO-APX
-
 ! RUN: %flang --target=x86_64h-linux-gnu -c %s -### 2>&1 \
 ! RUN: | FileCheck %s -check-prefix=CHECK-X86_64H
 
@@ -64,12 +61,6 @@
 ! CHECK-SKYLAKE: "-fc1" "-triple" "x86_64-unknown-linux-gnu"
 ! CHECK-SKYLAKE-SAME: "-target-cpu" "skylake"
 
-! CHECK-APX: "-fc1" "-triple" "x86_64-unknown-linux-gnu"
-! CHECK-APX-SAME: "-target-feature" "+egpr"
-
-! CHECK-NO-APX: "-fc1" "-triple" "x86_64-unknown-linux-gnu"
-! CHECK-NO-APX-SAME: "-target-feature" "-ccmp"
-
 ! CHECK-X86_64H: "-fc1" "-triple" "x86_64h-unknown-linux-gnu"
 ! CHECK-X86_64H-SAME: "-target-cpu" "x86-64" "-target-feature" "-rdrnd" "-target-feature" "-aes" "-target-feature" "-pclmul" "-target-feature" "-rtm" "-target-feature" "-fsgsbase"
 
@@ -87,3 +78,158 @@
 
 ! CHECK-SPARC-VIS: "-fc1" "-triple" "sparc64-{{[^"]+}}"
 ! CHECK-SPARC-VIS-SAME: "-target-feature" "+vis"
+
+!
+! ============================================================================
+! X86 m_x86_Features_Group: grouped checks to minimize driver invocations.
+! ============================================================================
+!
+! RUN: %flang --target=x86_64-linux-gnu -mx87 -mmmx -mamx-avx512 -mamx-bf16 -mamx-complex -mamx-fp16 -mamx-int8 -mamx-fp8 -mamx-tile -mamx-movrs -mcmpccxadd -msse -msse2 -msse3 -mssse3 -msse4.1 -msse4.2 -msse4a -mavx -mavx10.1 -mavx10.2 -mavx2 -mavx512f -mavx512bf16 -mavx512bitalg -mavx512bmm -mavx512bw -mavx512cd -mavx512dq -mavx512fp16 -c %s -### 2>&1 \
+! RUN:   | FileCheck %s -check-prefix=CHECK-X86-G1
+! CHECK-X86-G1: "-fc1" "-triple" "x86_64-unknown-linux-gnu"
+! CHECK-X86-G1-SAME: "-target-feature" "+x87"
+! CHECK-X86-G1-SAME: "-target-feature" "+mmx"
+! CHECK-X86-G1-SAME: "-target-feature" "+amx-avx512"
+! CHECK-X86-G1-SAME: "-target-feature" "+amx-bf16"
+! CHECK-X86-G1-SAME: "-target-feature" "+amx-complex"
+! CHECK-X86-G1-SAME: "-target-feature" "+amx-fp16"
+! CHECK-X86-G1-SAME: "-target-feature" "+amx-int8"
+! CHECK-X86-G1-SAME: "-target-feature" "+amx-fp8"
+! CHECK-X86-G1-SAME: "-target-feature" "+amx-tile"
+! CHECK-X86-G1-SAME: "-target-feature" "+amx-movrs"
+! CHECK-X86-G1-SAME: "-target-feature" "+cmpccxadd"
+! CHECK-X86-G1-SAME: "-target-feature" "+sse"
+! CHECK-X86-G1-SAME: "-target-feature" "+sse2"
+! CHECK-X86-G1-SAME: "-target-feature" "+sse3"
+! CHECK-X86-G1-SAME: "-target-feature" "+ssse3"
+! CHECK-X86-G1-SAME: "-target-feature" "+sse4.1"
+! CHECK-X86-G1-SAME: "-target-feature" "+sse4.2"
+! CHECK-X86-G1-SAME: "-target-feature" "+sse4a"
+! CHECK-X86-G1-SAME: "-target-feature" "+avx"
+! CHECK-X86-G1-SAME: "-target-feature" "+avx10.1"
+! CHECK-X86-G1-SAME: "-target-feature" "+avx10.2"
+! CHECK-X86-G1-SAME: "-target-feature" "+avx2"
+! CHECK-X86-G1-SAME: "-target-feature" "+avx512f"
+! CHECK-X86-G1-SAME: "-target-feature" "+avx512bf16"
+! CHECK-X86-G1-SAME: "-target-feature" "+avx512bitalg"
+! CHECK-X86-G1-SAME: "-target-feature" "+avx512bmm"
+! CHECK-X86-G1-SAME: "-target-feature" "+avx512bw"
+! CHECK-X86-G1-SAME: "-target-feature" "+avx512cd"
+! CHECK-X86-G1-SAME: "-target-feature" "+avx512dq"
+! CHECK-X86-G1-SAME: "-target-feature" "+avx512fp16"
+!
+! RUN: %flang --target=x86_64-linux-gnu -mavx512ifma -mavx512vbmi -mavx512vbmi2 -mavx512vl -mavx512vnni -mavx512vpopcntdq -mavx512vp2intersect -mavxifma -mavxneconvert -mavxvnniint16 -mavxvnniint8 -mavxvnni -madx -maes -mbmi -mbmi2 -mcldemote -mclflushopt -mclwb -mwbnoinvd -mclzero -mcrc32 -mcx16 -menqcmd -mf16c -mfma -mfma4 -mfsgsbase -mfxsr -minvpcid -c %s -### 2>&1 \
+! RUN:   | FileCheck %s -check-prefix=CHECK-X86-G2
+! CHECK-X86-G2: "-fc1" "-triple" "x86_64-unknown-linux-gnu"
+! CHECK-X86-G2-SAME: "-target-feature" "+avx512ifma"
+! CHECK-X86-G2-SAME: "-target-feature" "+avx512vbmi"
+! CHECK-X86-G2-SAME: "-target-feature" "+avx512vbmi2"
+! CHECK-X86-G2-SAME: "-target-feature" "+avx512vl"
+! CHECK-X86-G2-SAME: "-target-feature" "+avx512vnni"
+! CHECK-X86-G2-SAME: "-target-feature" "+avx512vpopcntdq"
+! CHECK-X86-G2-SAME: "-target-feature" "+avx512vp2intersect"
+! CHECK-X86-G2-SAME: "-target-feature" "+avxifma"
+! CHECK-X86-G2-SAME: "-target-feature" "+avxneconvert"
+! CHECK-X86-G2-SAME: "-target-feature" "+avxvnniint16"
+! CHECK-X86-G2-SAME: "-target-feature" "+avxvnniint8"
+! CHECK-X86-G2-SAME: "-target-feature" "+avxvnni"
+! CHECK-X86-G2-SAME: "-target-feature" "+adx"
+! CHECK-X86-G2-SAME: "-target-feature" "+aes"
+! CHECK-X86-G2-SAME: "-target-feature" "+bmi"
+! CHECK-X86-G2-SAME: "-target-feature" "+bmi2"
+! CHECK-X86-G2-SAME: "-target-feature" "+cldemote"
+! CHECK-X86-G2-SAME: "-target-feature" "+clflushopt"
+! CHECK-X86-G2-SAME: "-target-feature" "+clwb"
+! CHECK-X86-G2-SAME: "-target-feature" "+wbnoinvd"
+! CHECK-X86-G2-SAME: "-target-feature" "+clzero"
+! CHECK-X86-G2-SAME: "-target-feature" "+crc32"
+! CHECK-X86-G2-SAME: "-target-feature" "+cx16"
+! CHECK-X86-G2-SAME: "-target-feature" "+enqcmd"
+! CHECK-X86-G2-SAME: "-target-feature" "+f16c"
+! CHECK-X86-G2-SAME: "-target-feature" "+fma"
+! CHECK-X86-G2-SAME: "-target-feature" "+fma4"
+! CHECK-X86-G2-SAME: "-target-feature" "+fsgsbase"
+! CHECK-X86-G2-SAME: "-target-feature" "+fxsr"
+! CHECK-X86-G2-SAME: "-target-feature" "+invpcid"
+!
+! RUN: %flang --target=x86_64-linux-gnu -mgfni -mhreset -mkl -mwidekl -mlwp -mlzcnt -mmovbe -mmovdiri -mmovdir64b -mmovrs -mmwaitx -mpku -mpclmul -mpconfig -mpopcnt -mprefetchi -mprfchw -mptwrite -mraoint -mrdpid -mrdpru -mrdrnd -mrtm -mrdseed -msahf -mserialize -msgx -msha -msha512 -msm3 -c %s -### 2>&1 \
+! RUN:   | FileCheck %s -check-prefix=CHECK-X86-G3
+! CHECK-X86-G3: "-fc1" "-triple" "x86_64-unknown-linux-gnu"
+! CHECK-X86-G3-SAME: "-target-feature" "+gfni"
+! CHECK-X86-G3-SAME: "-target-feature" "+hreset"
+! CHECK-X86-G3-SAME: "-target-feature" "+kl"
+! CHECK-X86-G3-SAME: "-target-feature" "+widekl"
+! CHECK-X86-G3-SAME: "-target-feature" "+lwp"
+! CHECK-X86-G3-SAME: "-target-feature" "+lzcnt"
+! CHECK-X86-G3-SAME: "-target-feature" "+movbe"
+! CHECK-X86-G3-SAME: "-target-feature" "+movdiri"
+! CHECK-X86-G3-SAME: "-target-feature" "+movdir64b"
+! CHECK-X86-G3-SAME: "-target-feature" "+movrs"
+! CHECK-X86-G3-SAME: "-target-feature" "+mwaitx"
+! CHECK-X86-G3-SAME: "-target-feature" "+pku"
+! CHECK-X86-G3-SAME: "-target-feature" "+pclmul"
+! CHECK-X86-G3-SAME: "-target-feature" "+pconfig"
+! CHECK-X86-G3-SAME: "-target-feature" "+popcnt"
+! CHECK-X86-G3-SAME: "-target-feature" "+prefetchi"
+! CHECK-X86-G3-SAME: "-target-feature" "+prfchw"
+! CHECK-X86-G3-SAME: "-target-feature" "+ptwrite"
+! CHECK-X86-G3-SAME: "-target-feature" "+raoint"
+! CHECK-X86-G3-SAME: "-target-feature" "+rdpid"
+! CHECK-X86-G3-SAME: "-target-feature" "+rdpru"
+! CHECK-X86-G3-SAME: "-target-feature" "+rdrnd"
+! CHECK-X86-G3-SAME: "-target-feature" "+rtm"
+! CHECK-X86-G3-SAME: "-target-feature" "+rdseed"
+! CHECK-X86-G3-SAME: "-target-feature" "+sahf"
+! CHECK-X86-G3-SAME: "-target-feature" "+serialize"
+! CHECK-X86-G3-SAME: "-target-feature" "+sgx"
+! CHECK-X86-G3-SAME: "-target-feature" "+sha"
+! CHECK-X86-G3-SAME: "-target-feature" "+sha512"
+! CHECK-X86-G3-SAME: "-target-feature" "+sm3"
+!
+! RUN: %flang --target=x86_64-linux-gnu -msm4 -mtbm -mtsxldtrk -muintr -musermsr -mvaes -mvpclmulqdq -mwaitpkg -mxop -mxsave -mxsavec -mxsaveopt -mxsaves -mshstk -mretpoline-external-thunk -mvzeroupper -c %s -### 2>&1 \
+! RUN:   | FileCheck %s -check-prefix=CHECK-X86-G4
+! CHECK-X86-G4: "-fc1" "-triple" "x86_64-unknown-linux-gnu"
+! CHECK-X86-G4-SAME: "-target-feature" "+sm4"
+! CHECK-X86-G4-SAME: "-target-feature" "+tbm"
+! CHECK-X86-G4-SAME: "-target-feature" "+tsxldtrk"
+! CHECK-X86-G4-SAME: "-target-feature" "+uintr"
+! CHECK-X86-G4-SAME: "-target-feature" "+usermsr"
+! CHECK-X86-G4-SAME: "-target-feature" "+vaes"
+! CHECK-X86-G4-SAME: "-target-feature" "+vpclmulqdq"
+! CHECK-X86-G4-SAME: "-target-feature" "+waitpkg"
+! CHECK-X86-G4-SAME: "-target-feature" "+xop"
+! CHECK-X86-G4-SAME: "-target-feature" "+xsave"
+! CHECK-X86-G4-SAME: "-target-feature" "+xsavec"
+! CHECK-X86-G4-SAME: "-target-feature" "+xsaveopt"
+! CHECK-X86-G4-SAME: "-target-feature" "+xsaves"
+! CHECK-X86-G4-SAME: "-target-feature" "+shstk"
+! CHECK-X86-G4-SAME: "-target-feature" "+retpoline-external-thunk"
+! CHECK-X86-G4-SAME: "-target-feature" "+vzeroupper"
+!
+! RUN: %flang --target=x86_64-linux-gnu -mno-avx -mno-avx2 -mno-sse -mno-aes -mno-amx-tile -c %s -### 2>&1 \
+! RUN:   | FileCheck %s -check-prefix=CHECK-X86-NEG
+! CHECK-X86-NEG: "-fc1" "-triple" "x86_64-unknown-linux-gnu"
+! CHECK-X86-NEG-SAME: "-target-feature" "-avx"
+! CHECK-X86-NEG-SAME: "-target-feature" "-avx2"
+! CHECK-X86-NEG-SAME: "-target-feature" "-sse"
+! CHECK-X86-NEG-SAME: "-target-feature" "-aes"
+! CHECK-X86-NEG-SAME: "-target-feature" "-amx-tile"
+!
+! RUN: %flang --target=x86_64-linux-gnu -mapxf -c %s -### 2>&1 \
+! RUN:   | FileCheck %s -check-prefix=CHECK-APXF
+! CHECK-APXF: "-target-feature" "+egpr"
+! CHECK-APXF-SAME: "-target-feature" "+ccmp"
+!
+! RUN: %flang --target=x86_64-linux-gnu -mapx-features=egpr,ndd -c %s -### 2>&1 \
+! RUN:   | FileCheck %s -check-prefix=CHECK-APX-FEAT
+! CHECK-APX-FEAT: "-target-feature" "+egpr"
+! CHECK-APX-FEAT-SAME: "-target-feature" "+ndd"
+!
+! RUN: %flang --target=x86_64-linux-gnu -mno-apx-features=ccmp -c %s -### 2>&1 \
+! RUN:   | FileCheck %s -check-prefix=CHECK-NO-APX
+! CHECK-NO-APX: "-target-feature" "-ccmp"
+!
+! RUN: not %flang --target=aarch64-linux-gnu -mavx -mcrc32 -c %s -### 2>&1 \
+! RUN:   | FileCheck %s -check-prefix=CHECK-NONX86
+! CHECK-NONX86: error: unsupported option '-mavx' for target 'aarch64-linux-gnu'
+! CHECK-NONX86: error: unsupported option '-mcrc32' for target 'aarch64-linux-gnu'



More information about the flang-commits mailing list