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

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 13 08:44:05 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;
----------------
arsenm wrote:

You also shouldn't be trying to handle the commuted forms. Constants should canonically be moved to the RHS.

You bind $lhs and $rhs in tablegen, but don't do anything with them. Yes we're missing a good way to match G_FCONSTANT but you can still do that in C++, from the bound values passed in from tablegen 

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


More information about the llvm-commits mailing list