[llvm] Add PreLegalizer pattern matching for degrees GL extension (PR #216506)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 12 21:39:22 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:
this is the MIR I see for constant
`%4:_(s32) = G_FCONSTANT float f0x42652EE1
%5:id(s32) = G_FMUL %0, %4`
and this below is the MIR i see for splat
` %6:_(s32) = G_FCONSTANT float f0x42652EE1
%5:_(<4 x s32>) = G_BUILD_VECTOR %6(s32), %6(s32), %6(s32), %6(s32)
%7:id(<4 x s32>) = nnan ninf nsz arcp afn reassoc G_FMUL %0, %5`
we could have more cases here ? hence keeping it in tablegen may not be the right way was what I was thinking.
kindly help here @arsenm
https://github.com/llvm/llvm-project/pull/216506
More information about the llvm-commits
mailing list