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

via llvm-commits llvm-commits at lists.llvm.org
Sat Sep 12 21:13:16 PDT 2026


================
@@ -233,6 +233,44 @@ void SPIRVCombinerHelper::applySPIRVFaceForward(MachineInstr &MI) const {
   MI.eraseFromParent();
 }
 
+/// This match is part of a combine that
+/// rewrites fmul (x,180/pi) to degrees(x)
+///   (fN (g_fmul (fN X) (fN 180/pi))) -> (fN (g_intrinsic degrees (fN X)))
+///   (vXfN (g_fmul (vXfN X) (vXfN splat(180/pi)))) ->
+///   (vXfN (g_intrinsic degrees (vXfN X)))
+/// where `fN` denotes a supported floating-point type.
+bool SPIRVCombinerHelper::matchDegrees(MachineInstr &MI,
+                                       Register &MatchInfo) const {
+  Register NonConstReg;
+  std::optional<FPValueAndVReg> ConstVal;
+
+  if (!mi_match(MI.getOperand(0).getReg(), MRI,
+                m_GFMul(m_Reg(NonConstReg), m_GFCstOrSplat(ConstVal))) &&
+      !mi_match(MI.getOperand(0).getReg(), MRI,
+                m_GFMul(m_GFCstOrSplat(ConstVal), m_Reg(NonConstReg))))
+    return false;
----------------
albertbolt1 wrote:

yes with respect to this I was not able to send much to tablegen because I still have to find which one is a constant and FMUL can be commutative.

One way was to use G_FCONSTANT in the table gen to know which one is constant but the commutative problems still exists, will have a look again. 

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


More information about the llvm-commits mailing list