[llvm] Add PreLegalizer pattern matching for degrees GL extension (PR #216506)

via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 15 12:43:07 PDT 2026


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions h,cpp -- llvm/lib/Target/SPIRV/SPIRVCombinerHelper.cpp llvm/lib/Target/SPIRV/SPIRVCombinerHelper.h --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/llvm/lib/Target/SPIRV/SPIRVCombinerHelper.cpp b/llvm/lib/Target/SPIRV/SPIRVCombinerHelper.cpp
index 58ea761c2..49bd2bb1f 100644
--- a/llvm/lib/Target/SPIRV/SPIRVCombinerHelper.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVCombinerHelper.cpp
@@ -393,10 +393,12 @@ bool SPIRVCombinerHelper::matchDegrees(MachineInstr &MI) const {
   if (!Op1Def || !Op2Def)
     return false;
 
-  if (Op1Def->getOpcode() != TargetOpcode::G_FCONSTANT && Op2Def->getOpcode() != TargetOpcode::G_FCONSTANT)
+  if (Op1Def->getOpcode() != TargetOpcode::G_FCONSTANT &&
+      Op2Def->getOpcode() != TargetOpcode::G_FCONSTANT)
     return false;
 
-  MachineInstr *constantMachineInstruction = (Op1Def->getOpcode() == TargetOpcode::G_FCONSTANT) ? Op1Def : Op2Def;
+  MachineInstr *constantMachineInstruction =
+      (Op1Def->getOpcode() == TargetOpcode::G_FCONSTANT) ? Op1Def : Op2Def;
   MachineOperand &ConstantOperand = constantMachineInstruction->getOperand(1);
 
   if (!ConstantOperand.isFPImm())
@@ -406,9 +408,7 @@ bool SPIRVCombinerHelper::matchDegrees(MachineInstr &MI) const {
   const APFloat &Val = Constant->getValueAPF();
   APFloat Expected(180.0 / std::acos(-1.0));
   bool LostInfo = false;
-  Expected.convert(Val.getSemantics(),
-                            APFloat::rmNearestTiesToEven,
-                            &LostInfo);
+  Expected.convert(Val.getSemantics(), APFloat::rmNearestTiesToEven, &LostInfo);
 
   if (Expected.compare(Val) != APFloat::cmpEqual)
     return false;
@@ -422,8 +422,9 @@ void SPIRVCombinerHelper::applyDegrees(MachineInstr &MI) const {
   Register Op2 = MI.getOperand(2).getReg();
   MachineInstr *Op1Def = MRI.getVRegDef(Op1);
   MachineInstr *Op2Def = MRI.getVRegDef(Op2);
-  Register nonConstantReg = (Op1Def->getOpcode() == TargetOpcode::G_FCONSTANT) ? Op2 : Op1;
-  
+  Register nonConstantReg =
+      (Op1Def->getOpcode() == TargetOpcode::G_FCONSTANT) ? Op2 : Op1;
+
   Builder.setInstrAndDebugLoc(MI);
   Builder.buildIntrinsic(Intrinsic::spv_degrees, ResultReg)
       .addUse(nonConstantReg);

``````````

</details>


https://github.com/llvm/llvm-project/pull/216506


More information about the llvm-commits mailing list