Skip to content

Conversation

@bob80905
Copy link
Contributor

@bob80905 bob80905 commented Jul 1, 2025

This PR adds the -Gis option to clang-dxc, to instruct the behavior to enable IEEE strict mode. The purpose is so that clang-dxc behaves as DXC does when it takes the -Gis option.
Fixes #145589

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' HLSL HLSL Language Support labels Jul 1, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 1, 2025

@llvm/pr-subscribers-hlsl

@llvm/pr-subscribers-clang-driver

Author: Joshua Batista (bob80905)

Changes

This PR adds the -Gis option to clang-dxc, to instruct the behavior to enable IEEE strict mode. The purpose is so that clang-dxc behaves as DXC does when it takes the -Gis option.
Fixes #145589


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

3 Files Affected:

  • (modified) clang/include/clang/Driver/Options.td (+2)
  • (modified) clang/lib/Driver/ToolChains/HLSL.cpp (+8)
  • (added) clang/test/Options/Gis.hlsl (+12)
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 0ffd8c40da7da..a1e56e2ec9b8c 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -9306,6 +9306,8 @@ def dxc_validator_path_EQ : Joined<["--"], "dxv-path=">, Group<dxc_Group>,
   HelpText<"DXIL validator installation path">;
 def dxc_disable_validation : DXCFlag<"Vd">,
   HelpText<"Disable validation">;
+def dxc_gis : DXCFlag<"Gis">,
+  HelpText<"Enable IEEE strict mode (equivalent to -ffp-model=strict)">;
 def : Option<["/", "-"], "Qembed_debug", KIND_FLAG>, Group<dxc_Group>,
   Flags<[Ignored]>, Visibility<[DXCOption]>,
   HelpText<"Embed PDB in shader container (ignored)">;
diff --git a/clang/lib/Driver/ToolChains/HLSL.cpp b/clang/lib/Driver/ToolChains/HLSL.cpp
index dcc51e182924c..4a4938a501e9e 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -330,6 +330,14 @@ HLSLToolChain::TranslateArgs(const DerivedArgList &Args, StringRef BoundArch,
       A->claim();
       continue;
     }
+    if (A->getOption().getID() == options::OPT_dxc_gis) {
+      // Translate -Gis into -ffp_model_EQ=strict
+      DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_ffp_model_EQ),
+                          "strict");
+      A->claim();
+      continue;
+    }
+
     DAL->append(A);
   }
 
diff --git a/clang/test/Options/Gis.hlsl b/clang/test/Options/Gis.hlsl
new file mode 100644
index 0000000000000..5a11b7ba64ff0
--- /dev/null
+++ b/clang/test/Options/Gis.hlsl
@@ -0,0 +1,12 @@
+// RUN: %clang_dxc -T lib_6_4 -Gis %s 2>&1 -### | FileCheck -check-prefix=Gis %s
+// RUN: %clang_dxc -T lib_6_4 %s 2>&1 -### | FileCheck -check-prefix=NO_Gis %s
+// RUN: not %clang_dxc -T lib_6_4 /Gis gibberish -### %s 2>&1 | FileCheck -check-prefix=CHECK-ERR %s
+
+// Gis: "-fmath-errno" "-ffp-contract=off" "-frounding-math" "-ffp-exception-behavior=strict" "-complex-range=full"
+// assert expected floating point options are present
+// NO_Gis-NOT: "-fmath-errno" "-ffp-contract=off" "-frounding-math" "-ffp-exception-behavior=strict" "-complex-range=full"
+// CHECK-ERR: error: no such file or directory: 'gibberish'
+float4 main(float4 a : A) : SV_TARGET
+{
+  return -a.yxxx;
+}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error check seems unrelated to the change you're making here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would probably be better to split this into one NO_Gis-NOT line per flag, that way the order of the flags doesn't matter it will verify that none of the flags ever appear.

@bob80905 bob80905 self-assigned this Jul 1, 2025
Copy link
Collaborator

@llvm-beanz llvm-beanz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will have some nuanced differences from what DXC does today because of the differences in granularity of floating point semantic controls in LLVM today vs 3.7. That said, I think this will be conservatively correct and is probably the best approach.

@bob80905 bob80905 merged commit 2ed7b22 into llvm:main Jul 2, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang Clang issues not falling into any other category HLSL HLSL Language Support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[HLSL] Add -Gis option from DXC to clang-dxc

4 participants