[llvm-branch-commits] [llvm] [AMDGPU] Fold fmul with zero checks to fmul.legacy (PR #229357)

Harrison Hao via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Oct 21 02:17:04 PDT 2026


================
@@ -1578,11 +1581,92 @@ bool AMDGPUCodeGenPrepareImpl::visitLoadInst(LoadInst &I) {
   return false;
 }
 
+// select (X == 0 || Y == 0), +0.0, (X * Y) -> fmul_legacy(X, Y)
+bool AMDGPUCodeGenPrepareImpl::foldSelectToFMulLegacy(SelectInst &I) const {
+  if (!I.getType()->isFloatTy())
+    return false;
+
+  // Inverted form: select (X != 0 && Y != 0), X * Y, +0.0.
+  bool Inverted = match(I.getFalseValue(), m_PosZeroFP());
+  if (!Inverted && !match(I.getTrueValue(), m_PosZeroFP()))
+    return false;
+
+  Value *X, *Y;
+  if (!match(Inverted ? I.getTrueValue() : I.getFalseValue(),
+             m_OneUse(m_FMul(m_Value(X), m_Value(Y)))))
+    return false;
+
+  // Collect the values compared against zero in the condition.
----------------
harrisonGPU wrote:

Done, it's now a direct m_Or/m_And match of the zero compares (or a single compare for x * x).

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


More information about the llvm-branch-commits mailing list