[llvm-branch-commits] [llvm] [AMDGPU] Fold fmul with zero checks to fmul.legacy (PR #229357)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Oct 6 02:59:06 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-amdgpu
Author: Harrison Hao (harrisonGPU)
<details>
<summary>Changes</summary>
Recognize f32 multiplication with zero checks in AMDGPUCodeGenPrepare,
including fabs/fneg wrappers.
Example:
```
(x == 0 || y == 0) ? +0.0 : x * y
==>
llvm.amdgcn.fmul.legacy(x, y)
```
---
<sub>Stack created with <a href="https://github.com/github/gh-stack">GitHub Stacks CLI</a> • <a href="https://gh.io/stacks-feedback">Give Feedback 💬</a></sub>
---
Full diff: https://github.com/llvm/llvm-project/pull/229357.diff
2 Files Affected:
- (modified) llvm/lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp (+77)
- (modified) llvm/test/CodeGen/AMDGPU/amdgpu-codegenprepare-fmul-legacy.ll (+21-107)
``````````diff
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp b/llvm/lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp
index 95aa0de627485..7370b40cd4132 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp
@@ -177,6 +177,9 @@ class AMDGPUCodeGenPrepareImpl
/// we expand some divisions here, we need to perform this before obscuring.
bool foldBinOpIntoSelect(BinaryOperator &I) const;
+ /// Fold select (X == 0 || Y == 0), +0.0, X * Y into fmul_legacy(X, Y).
+ bool foldSelectToFMulLegacy(SelectInst &I);
+
bool divHasSpecialOptimization(BinaryOperator &I,
Value *Num, Value *Den) const;
unsigned getDivNumBits(BinaryOperator &I, Value *Num, Value *Den,
@@ -1578,11 +1581,85 @@ 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) {
+ 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;
+
+ SmallVector<Value *, 4> Roots[2] = {{I.getCondition()}, {X, Y}};
+ SmallPtrSet<Value *, 4> Leaves[2];
+ for (auto [Worklist, Found] : zip(Roots, Leaves)) {
+ SmallPtrSet<Value *, 8> Visited;
+
+ while (!Worklist.empty()) {
+ Value *Cur = Worklist.pop_back_val();
+ if (!Visited.insert(Cur).second)
+ continue;
+
+ Value *Src, *LHS, *RHS;
+ if (Cur->getType()->isIntegerTy(1)) {
+ if (Inverted ? match(Cur, m_And(m_Value(LHS), m_Value(RHS)))
+ : match(Cur, m_Or(m_Value(LHS), m_Value(RHS)))) {
+ Worklist.append({LHS, RHS});
+ continue;
+ }
+
+ if (!match(Cur, m_SpecificFCmp(Inverted ? FCmpInst::FCMP_UNE
+ : FCmpInst::FCMP_OEQ,
+ m_Value(Src), m_AnyZeroFP())))
+ return false;
+
+ Worklist.push_back(Src);
+ continue;
+ }
+
+ // Peeling a nnan/ninf op could expose poison that the select hides.
+ auto *FPOp = dyn_cast<FPMathOperator>(Cur);
+ if (FPOp && (FPOp->hasNoNaNs() || FPOp->hasNoInfs())) {
+ Found.insert(Cur);
+ continue;
+ }
+
+ // m_UnOp, not m_FNeg: fsub -0.0, X may flush a denormal result to zero.
+ if (match(Cur, m_CombineOr(m_UnOp(m_Value(Src)), m_FAbs(m_Value(Src))))) {
+ Worklist.push_back(Src);
+ continue;
+ }
+
+ Found.insert(Cur);
+ }
+ }
+
+ if (Leaves[0] != Leaves[1])
+ return false;
+
+ IRBuilder<> Builder(&I);
+ Value *LegacyMul =
+ Builder.CreateIntrinsic(Intrinsic::amdgcn_fmul_legacy, {}, {X, Y});
+ LegacyMul->takeName(&I);
+ I.replaceAllUsesWith(LegacyMul);
+ DeadVals.push_back(&I);
+ return true;
+}
+
bool AMDGPUCodeGenPrepareImpl::visitSelectInst(SelectInst &I) {
FPMathOperator *FPOp = dyn_cast<FPMathOperator>(&I);
if (!FPOp)
return false;
+ if (foldSelectToFMulLegacy(I))
+ return true;
+
Value *X;
Value *Fract = nullptr;
diff --git a/llvm/test/CodeGen/AMDGPU/amdgpu-codegenprepare-fmul-legacy.ll b/llvm/test/CodeGen/AMDGPU/amdgpu-codegenprepare-fmul-legacy.ll
index 0f985a0208e8b..7fd4295ba1cf9 100644
--- a/llvm/test/CodeGen/AMDGPU/amdgpu-codegenprepare-fmul-legacy.ll
+++ b/llvm/test/CodeGen/AMDGPU/amdgpu-codegenprepare-fmul-legacy.ll
@@ -4,11 +4,7 @@
define float @select_fmul_legacy(float %x, float %y) {
; CHECK-LABEL: define float @select_fmul_legacy(
; CHECK-SAME: float [[X:%.*]], float [[Y:%.*]]) {
-; CHECK-NEXT: [[XZ:%.*]] = fcmp oeq float [[X]], 0.000000e+00
-; CHECK-NEXT: [[YZ:%.*]] = fcmp oeq float [[Y]], 0.000000e+00
-; CHECK-NEXT: [[C:%.*]] = or i1 [[XZ]], [[YZ]]
-; CHECK-NEXT: [[MUL:%.*]] = fmul float [[X]], [[Y]]
-; CHECK-NEXT: [[R:%.*]] = select i1 [[C]], float 0.000000e+00, float [[MUL]]
+; CHECK-NEXT: [[R:%.*]] = call float @llvm.amdgcn.fmul.legacy(float [[X]], float [[Y]])
; CHECK-NEXT: ret float [[R]]
;
%xz = fcmp oeq float %x, 0.0
@@ -22,11 +18,7 @@ define float @select_fmul_legacy(float %x, float %y) {
define float @select_fmul_legacy_uniform(float inreg %x, float inreg %y) {
; CHECK-LABEL: define float @select_fmul_legacy_uniform(
; CHECK-SAME: float inreg [[X:%.*]], float inreg [[Y:%.*]]) {
-; CHECK-NEXT: [[XZ:%.*]] = fcmp oeq float [[X]], 0.000000e+00
-; CHECK-NEXT: [[YZ:%.*]] = fcmp oeq float [[Y]], 0.000000e+00
-; CHECK-NEXT: [[C:%.*]] = or i1 [[XZ]], [[YZ]]
-; CHECK-NEXT: [[MUL:%.*]] = fmul float [[X]], [[Y]]
-; CHECK-NEXT: [[R:%.*]] = select i1 [[C]], float 0.000000e+00, float [[MUL]]
+; CHECK-NEXT: [[R:%.*]] = call float @llvm.amdgcn.fmul.legacy(float [[X]], float [[Y]])
; CHECK-NEXT: ret float [[R]]
;
%xz = fcmp oeq float %x, 0.0
@@ -40,11 +32,7 @@ define float @select_fmul_legacy_uniform(float inreg %x, float inreg %y) {
define float @select_fmul_legacy_commute_fmul(float %x, float %y) {
; CHECK-LABEL: define float @select_fmul_legacy_commute_fmul(
; CHECK-SAME: float [[X:%.*]], float [[Y:%.*]]) {
-; CHECK-NEXT: [[XZ:%.*]] = fcmp oeq float [[X]], 0.000000e+00
-; CHECK-NEXT: [[YZ:%.*]] = fcmp oeq float [[Y]], 0.000000e+00
-; CHECK-NEXT: [[C:%.*]] = or i1 [[XZ]], [[YZ]]
-; CHECK-NEXT: [[MUL:%.*]] = fmul float [[Y]], [[X]]
-; CHECK-NEXT: [[R:%.*]] = select i1 [[C]], float 0.000000e+00, float [[MUL]]
+; CHECK-NEXT: [[R:%.*]] = call float @llvm.amdgcn.fmul.legacy(float [[Y]], float [[X]])
; CHECK-NEXT: ret float [[R]]
;
%xz = fcmp oeq float %x, 0.0
@@ -58,11 +46,7 @@ define float @select_fmul_legacy_commute_fmul(float %x, float %y) {
define float @select_fmul_legacy_commute_or(float %x, float %y) {
; CHECK-LABEL: define float @select_fmul_legacy_commute_or(
; CHECK-SAME: float [[X:%.*]], float [[Y:%.*]]) {
-; CHECK-NEXT: [[XZ:%.*]] = fcmp oeq float [[X]], 0.000000e+00
-; CHECK-NEXT: [[YZ:%.*]] = fcmp oeq float [[Y]], 0.000000e+00
-; CHECK-NEXT: [[C:%.*]] = or i1 [[YZ]], [[XZ]]
-; CHECK-NEXT: [[MUL:%.*]] = fmul float [[X]], [[Y]]
-; CHECK-NEXT: [[R:%.*]] = select i1 [[C]], float 0.000000e+00, float [[MUL]]
+; CHECK-NEXT: [[R:%.*]] = call float @llvm.amdgcn.fmul.legacy(float [[X]], float [[Y]])
; CHECK-NEXT: ret float [[R]]
;
%xz = fcmp oeq float %x, 0.0
@@ -76,11 +60,7 @@ define float @select_fmul_legacy_commute_or(float %x, float %y) {
define float @select_fmul_legacy_cmp_neg_zero(float %x, float %y) {
; CHECK-LABEL: define float @select_fmul_legacy_cmp_neg_zero(
; CHECK-SAME: float [[X:%.*]], float [[Y:%.*]]) {
-; CHECK-NEXT: [[XZ:%.*]] = fcmp oeq float [[X]], -0.000000e+00
-; CHECK-NEXT: [[YZ:%.*]] = fcmp oeq float [[Y]], -0.000000e+00
-; CHECK-NEXT: [[C:%.*]] = or i1 [[XZ]], [[YZ]]
-; CHECK-NEXT: [[MUL:%.*]] = fmul float [[X]], [[Y]]
-; CHECK-NEXT: [[R:%.*]] = select i1 [[C]], float 0.000000e+00, float [[MUL]]
+; CHECK-NEXT: [[R:%.*]] = call float @llvm.amdgcn.fmul.legacy(float [[X]], float [[Y]])
; CHECK-NEXT: ret float [[R]]
;
%xz = fcmp oeq float %x, -0.0
@@ -189,11 +169,7 @@ define float @select_fmul_legacy_logical_or(float %x, float %y) {
define float @select_fmul_legacy_inverted(float %x, float %y) {
; CHECK-LABEL: define float @select_fmul_legacy_inverted(
; CHECK-SAME: float [[X:%.*]], float [[Y:%.*]]) {
-; CHECK-NEXT: [[XNZ:%.*]] = fcmp une float [[X]], 0.000000e+00
-; CHECK-NEXT: [[YNZ:%.*]] = fcmp une float [[Y]], 0.000000e+00
-; CHECK-NEXT: [[C:%.*]] = and i1 [[XNZ]], [[YNZ]]
-; CHECK-NEXT: [[MUL:%.*]] = fmul float [[X]], [[Y]]
-; CHECK-NEXT: [[R:%.*]] = select i1 [[C]], float [[MUL]], float 0.000000e+00
+; CHECK-NEXT: [[R:%.*]] = call float @llvm.amdgcn.fmul.legacy(float [[X]], float [[Y]])
; CHECK-NEXT: ret float [[R]]
;
%xnz = fcmp une float %x, 0.0
@@ -399,9 +375,7 @@ define <2 x float> @select_fmul_legacy_v2f32(<2 x float> %x, <2 x float> %y) {
define float @select_fmul_legacy_square(float %x) {
; CHECK-LABEL: define float @select_fmul_legacy_square(
; CHECK-SAME: float [[X:%.*]]) {
-; CHECK-NEXT: [[XZ:%.*]] = fcmp oeq float [[X]], 0.000000e+00
-; CHECK-NEXT: [[MUL:%.*]] = fmul float [[X]], [[X]]
-; CHECK-NEXT: [[R:%.*]] = select i1 [[XZ]], float 0.000000e+00, float [[MUL]]
+; CHECK-NEXT: [[R:%.*]] = call float @llvm.amdgcn.fmul.legacy(float [[X]], float [[X]])
; CHECK-NEXT: ret float [[R]]
;
%xz = fcmp oeq float %x, 0.0
@@ -413,11 +387,7 @@ define float @select_fmul_legacy_square(float %x) {
define float @select_fmul_legacy_square_or(float %x) {
; CHECK-LABEL: define float @select_fmul_legacy_square_or(
; CHECK-SAME: float [[X:%.*]]) {
-; CHECK-NEXT: [[XZ0:%.*]] = fcmp oeq float [[X]], 0.000000e+00
-; CHECK-NEXT: [[XZ1:%.*]] = fcmp oeq float [[X]], 0.000000e+00
-; CHECK-NEXT: [[C:%.*]] = or i1 [[XZ0]], [[XZ1]]
-; CHECK-NEXT: [[MUL:%.*]] = fmul float [[X]], [[X]]
-; CHECK-NEXT: [[R:%.*]] = select i1 [[C]], float 0.000000e+00, float [[MUL]]
+; CHECK-NEXT: [[R:%.*]] = call float @llvm.amdgcn.fmul.legacy(float [[X]], float [[X]])
; CHECK-NEXT: ret float [[R]]
;
%xz0 = fcmp oeq float %x, 0.0
@@ -431,12 +401,7 @@ define float @select_fmul_legacy_square_or(float %x) {
define float @select_fmul_legacy_redundant_cmp(float %x, float %y) {
; CHECK-LABEL: define float @select_fmul_legacy_redundant_cmp(
; CHECK-SAME: float [[X:%.*]], float [[Y:%.*]]) {
-; CHECK-NEXT: [[XZ:%.*]] = fcmp oeq float [[X]], 0.000000e+00
-; CHECK-NEXT: [[YZ:%.*]] = fcmp oeq float [[Y]], 0.000000e+00
-; CHECK-NEXT: [[C0:%.*]] = or i1 [[XZ]], [[YZ]]
-; CHECK-NEXT: [[C:%.*]] = or i1 [[C0]], [[XZ]]
-; CHECK-NEXT: [[MUL:%.*]] = fmul float [[X]], [[Y]]
-; CHECK-NEXT: [[R:%.*]] = select i1 [[C]], float 0.000000e+00, float [[MUL]]
+; CHECK-NEXT: [[R:%.*]] = call float @llvm.amdgcn.fmul.legacy(float [[X]], float [[Y]])
; CHECK-NEXT: ret float [[R]]
;
%xz = fcmp oeq float %x, 0.0
@@ -451,12 +416,7 @@ define float @select_fmul_legacy_redundant_cmp(float %x, float %y) {
define float @select_fmul_legacy_shared_or(float %x, float %y) {
; CHECK-LABEL: define float @select_fmul_legacy_shared_or(
; CHECK-SAME: float [[X:%.*]], float [[Y:%.*]]) {
-; CHECK-NEXT: [[XZ:%.*]] = fcmp oeq float [[X]], 0.000000e+00
-; CHECK-NEXT: [[YZ:%.*]] = fcmp oeq float [[Y]], 0.000000e+00
-; CHECK-NEXT: [[C0:%.*]] = or i1 [[XZ]], [[YZ]]
-; CHECK-NEXT: [[C:%.*]] = or i1 [[C0]], [[C0]]
-; CHECK-NEXT: [[MUL:%.*]] = fmul float [[X]], [[Y]]
-; CHECK-NEXT: [[R:%.*]] = select i1 [[C]], float 0.000000e+00, float [[MUL]]
+; CHECK-NEXT: [[R:%.*]] = call float @llvm.amdgcn.fmul.legacy(float [[X]], float [[Y]])
; CHECK-NEXT: ret float [[R]]
;
%xz = fcmp oeq float %x, 0.0
@@ -543,12 +503,8 @@ define float @select_fmul_legacy_const_operand(float %x) {
define float @select_fmul_legacy_fabs_mul_operand(float %x, float %y) {
; CHECK-LABEL: define float @select_fmul_legacy_fabs_mul_operand(
; CHECK-SAME: float [[X:%.*]], float [[Y:%.*]]) {
-; CHECK-NEXT: [[XZ:%.*]] = fcmp oeq float [[X]], 0.000000e+00
-; CHECK-NEXT: [[YZ:%.*]] = fcmp oeq float [[Y]], 0.000000e+00
-; CHECK-NEXT: [[C:%.*]] = or i1 [[XZ]], [[YZ]]
; CHECK-NEXT: [[FABS_X:%.*]] = call float @llvm.fabs.f32(float [[X]])
-; CHECK-NEXT: [[MUL:%.*]] = fmul float [[FABS_X]], [[Y]]
-; CHECK-NEXT: [[R:%.*]] = select i1 [[C]], float 0.000000e+00, float [[MUL]]
+; CHECK-NEXT: [[R:%.*]] = call float @llvm.amdgcn.fmul.legacy(float [[FABS_X]], float [[Y]])
; CHECK-NEXT: ret float [[R]]
;
%xz = fcmp oeq float %x, 0.0
@@ -563,12 +519,7 @@ define float @select_fmul_legacy_fabs_mul_operand(float %x, float %y) {
define float @select_fmul_legacy_fabs_cmp_operand(float %x, float %y) {
; CHECK-LABEL: define float @select_fmul_legacy_fabs_cmp_operand(
; CHECK-SAME: float [[X:%.*]], float [[Y:%.*]]) {
-; CHECK-NEXT: [[FABS_X:%.*]] = call float @llvm.fabs.f32(float [[X]])
-; CHECK-NEXT: [[XZ:%.*]] = fcmp oeq float [[FABS_X]], 0.000000e+00
-; CHECK-NEXT: [[YZ:%.*]] = fcmp oeq float [[Y]], 0.000000e+00
-; CHECK-NEXT: [[C:%.*]] = or i1 [[XZ]], [[YZ]]
-; CHECK-NEXT: [[MUL:%.*]] = fmul float [[X]], [[Y]]
-; CHECK-NEXT: [[R:%.*]] = select i1 [[C]], float 0.000000e+00, float [[MUL]]
+; CHECK-NEXT: [[R:%.*]] = call float @llvm.amdgcn.fmul.legacy(float [[X]], float [[Y]])
; CHECK-NEXT: ret float [[R]]
;
%fabs.x = call float @llvm.fabs.f32(float %x)
@@ -583,12 +534,8 @@ define float @select_fmul_legacy_fabs_cmp_operand(float %x, float %y) {
define float @select_fmul_legacy_fneg_mul_operand(float %x, float %y) {
; CHECK-LABEL: define float @select_fmul_legacy_fneg_mul_operand(
; CHECK-SAME: float [[X:%.*]], float [[Y:%.*]]) {
-; CHECK-NEXT: [[XZ:%.*]] = fcmp oeq float [[X]], 0.000000e+00
-; CHECK-NEXT: [[YZ:%.*]] = fcmp oeq float [[Y]], 0.000000e+00
-; CHECK-NEXT: [[C:%.*]] = or i1 [[XZ]], [[YZ]]
; CHECK-NEXT: [[FNEG_X:%.*]] = fneg float [[X]]
-; CHECK-NEXT: [[MUL:%.*]] = fmul float [[FNEG_X]], [[Y]]
-; CHECK-NEXT: [[R:%.*]] = select i1 [[C]], float 0.000000e+00, float [[MUL]]
+; CHECK-NEXT: [[R:%.*]] = call float @llvm.amdgcn.fmul.legacy(float [[FNEG_X]], float [[Y]])
; CHECK-NEXT: ret float [[R]]
;
%xz = fcmp oeq float %x, 0.0
@@ -603,12 +550,7 @@ define float @select_fmul_legacy_fneg_mul_operand(float %x, float %y) {
define float @select_fmul_legacy_fneg_cmp_operand(float %x, float %y) {
; CHECK-LABEL: define float @select_fmul_legacy_fneg_cmp_operand(
; CHECK-SAME: float [[X:%.*]], float [[Y:%.*]]) {
-; CHECK-NEXT: [[FNEG_X:%.*]] = fneg float [[X]]
-; CHECK-NEXT: [[XZ:%.*]] = fcmp oeq float [[FNEG_X]], 0.000000e+00
-; CHECK-NEXT: [[YZ:%.*]] = fcmp oeq float [[Y]], 0.000000e+00
-; CHECK-NEXT: [[C:%.*]] = or i1 [[XZ]], [[YZ]]
-; CHECK-NEXT: [[MUL:%.*]] = fmul float [[X]], [[Y]]
-; CHECK-NEXT: [[R:%.*]] = select i1 [[C]], float 0.000000e+00, float [[MUL]]
+; CHECK-NEXT: [[R:%.*]] = call float @llvm.amdgcn.fmul.legacy(float [[X]], float [[Y]])
; CHECK-NEXT: ret float [[R]]
;
%fneg.x = fneg float %x
@@ -625,11 +567,7 @@ define float @select_fmul_legacy_fneg_fabs(float %x, float %y) {
; CHECK-SAME: float [[X:%.*]], float [[Y:%.*]]) {
; CHECK-NEXT: [[FABS_X:%.*]] = call float @llvm.fabs.f32(float [[X]])
; CHECK-NEXT: [[FNEG_FABS_X:%.*]] = fneg float [[FABS_X]]
-; CHECK-NEXT: [[XZ:%.*]] = fcmp oeq float [[FABS_X]], 0.000000e+00
-; CHECK-NEXT: [[YZ:%.*]] = fcmp oeq float [[Y]], 0.000000e+00
-; CHECK-NEXT: [[C:%.*]] = or i1 [[XZ]], [[YZ]]
-; CHECK-NEXT: [[MUL:%.*]] = fmul float [[FNEG_FABS_X]], [[Y]]
-; CHECK-NEXT: [[R:%.*]] = select i1 [[C]], float 0.000000e+00, float [[MUL]]
+; CHECK-NEXT: [[R:%.*]] = call float @llvm.amdgcn.fmul.legacy(float [[FNEG_FABS_X]], float [[Y]])
; CHECK-NEXT: ret float [[R]]
;
%fabs.x = call float @llvm.fabs.f32(float %x)
@@ -645,12 +583,8 @@ define float @select_fmul_legacy_fneg_fabs(float %x, float %y) {
define float @select_fmul_legacy_fneg_nsz(float %x, float %y) {
; CHECK-LABEL: define float @select_fmul_legacy_fneg_nsz(
; CHECK-SAME: float [[X:%.*]], float [[Y:%.*]]) {
-; CHECK-NEXT: [[XZ:%.*]] = fcmp oeq float [[X]], 0.000000e+00
-; CHECK-NEXT: [[YZ:%.*]] = fcmp oeq float [[Y]], 0.000000e+00
-; CHECK-NEXT: [[C:%.*]] = or i1 [[XZ]], [[YZ]]
; CHECK-NEXT: [[FNEG_X:%.*]] = fneg nsz float [[X]]
-; CHECK-NEXT: [[MUL:%.*]] = fmul float [[FNEG_X]], [[Y]]
-; CHECK-NEXT: [[R:%.*]] = select i1 [[C]], float 0.000000e+00, float [[MUL]]
+; CHECK-NEXT: [[R:%.*]] = call float @llvm.amdgcn.fmul.legacy(float [[FNEG_X]], float [[Y]])
; CHECK-NEXT: ret float [[R]]
;
%xz = fcmp oeq float %x, 0.0
@@ -749,11 +683,7 @@ define float @select_fmul_legacy_canonicalize(float %x, float %y) {
define float @select_fmul_legacy_select_flags(float %x, float %y) {
; CHECK-LABEL: define float @select_fmul_legacy_select_flags(
; CHECK-SAME: float [[X:%.*]], float [[Y:%.*]]) {
-; CHECK-NEXT: [[XZ:%.*]] = fcmp oeq float [[X]], 0.000000e+00
-; CHECK-NEXT: [[YZ:%.*]] = fcmp oeq float [[Y]], 0.000000e+00
-; CHECK-NEXT: [[C:%.*]] = or i1 [[XZ]], [[YZ]]
-; CHECK-NEXT: [[MUL:%.*]] = fmul float [[X]], [[Y]]
-; CHECK-NEXT: [[R:%.*]] = select nsz i1 [[C]], float 0.000000e+00, float [[MUL]]
+; CHECK-NEXT: [[R:%.*]] = call float @llvm.amdgcn.fmul.legacy(float [[X]], float [[Y]])
; CHECK-NEXT: ret float [[R]]
;
%xz = fcmp oeq float %x, 0.0
@@ -768,11 +698,7 @@ define float @select_fmul_legacy_select_flags(float %x, float %y) {
define float @select_fmul_legacy_select_nnan_ninf(float %x, float %y) {
; CHECK-LABEL: define float @select_fmul_legacy_select_nnan_ninf(
; CHECK-SAME: float [[X:%.*]], float [[Y:%.*]]) {
-; CHECK-NEXT: [[XZ:%.*]] = fcmp oeq float [[X]], 0.000000e+00
-; CHECK-NEXT: [[YZ:%.*]] = fcmp oeq float [[Y]], 0.000000e+00
-; CHECK-NEXT: [[C:%.*]] = or i1 [[XZ]], [[YZ]]
-; CHECK-NEXT: [[MUL:%.*]] = fmul float [[X]], [[Y]]
-; CHECK-NEXT: [[R:%.*]] = select nnan ninf i1 [[C]], float 0.000000e+00, float [[MUL]]
+; CHECK-NEXT: [[R:%.*]] = call float @llvm.amdgcn.fmul.legacy(float [[X]], float [[Y]])
; CHECK-NEXT: ret float [[R]]
;
%xz = fcmp oeq float %x, 0.0
@@ -786,11 +712,7 @@ define float @select_fmul_legacy_select_nnan_ninf(float %x, float %y) {
define float @select_fmul_legacy_fmul_flags(float %x, float %y) {
; CHECK-LABEL: define float @select_fmul_legacy_fmul_flags(
; CHECK-SAME: float [[X:%.*]], float [[Y:%.*]]) {
-; CHECK-NEXT: [[XZ:%.*]] = fcmp oeq float [[X]], 0.000000e+00
-; CHECK-NEXT: [[YZ:%.*]] = fcmp oeq float [[Y]], 0.000000e+00
-; CHECK-NEXT: [[C:%.*]] = or i1 [[XZ]], [[YZ]]
-; CHECK-NEXT: [[MUL:%.*]] = fmul nnan ninf float [[X]], [[Y]]
-; CHECK-NEXT: [[R:%.*]] = select i1 [[C]], float 0.000000e+00, float [[MUL]]
+; CHECK-NEXT: [[R:%.*]] = call float @llvm.amdgcn.fmul.legacy(float [[X]], float [[Y]])
; CHECK-NEXT: ret float [[R]]
;
%xz = fcmp oeq float %x, 0.0
@@ -804,11 +726,7 @@ define float @select_fmul_legacy_fmul_flags(float %x, float %y) {
define float @select_fmul_legacy_fcmp_flags(float %x, float %y) {
; CHECK-LABEL: define float @select_fmul_legacy_fcmp_flags(
; CHECK-SAME: float [[X:%.*]], float [[Y:%.*]]) {
-; CHECK-NEXT: [[XZ:%.*]] = fcmp nnan oeq float [[X]], 0.000000e+00
-; CHECK-NEXT: [[YZ:%.*]] = fcmp nnan oeq float [[Y]], 0.000000e+00
-; CHECK-NEXT: [[C:%.*]] = or i1 [[XZ]], [[YZ]]
-; CHECK-NEXT: [[MUL:%.*]] = fmul float [[X]], [[Y]]
-; CHECK-NEXT: [[R:%.*]] = select i1 [[C]], float 0.000000e+00, float [[MUL]]
+; CHECK-NEXT: [[R:%.*]] = call float @llvm.amdgcn.fmul.legacy(float [[X]], float [[Y]])
; CHECK-NEXT: ret float [[R]]
;
%xz = fcmp nnan oeq float %x, 0.0
@@ -822,11 +740,7 @@ define float @select_fmul_legacy_fcmp_flags(float %x, float %y) {
define float @select_fmul_legacy_daz(float %x, float %y) #0 {
; CHECK-LABEL: define float @select_fmul_legacy_daz(
; CHECK-SAME: float [[X:%.*]], float [[Y:%.*]]) #[[ATTR0:[0-9]+]] {
-; CHECK-NEXT: [[XZ:%.*]] = fcmp oeq float [[X]], 0.000000e+00
-; CHECK-NEXT: [[YZ:%.*]] = fcmp oeq float [[Y]], 0.000000e+00
-; CHECK-NEXT: [[C:%.*]] = or i1 [[XZ]], [[YZ]]
-; CHECK-NEXT: [[MUL:%.*]] = fmul float [[X]], [[Y]]
-; CHECK-NEXT: [[R:%.*]] = select i1 [[C]], float 0.000000e+00, float [[MUL]]
+; CHECK-NEXT: [[R:%.*]] = call float @llvm.amdgcn.fmul.legacy(float [[X]], float [[Y]])
; CHECK-NEXT: ret float [[R]]
;
%xz = fcmp oeq float %x, 0.0
``````````
</details>
https://github.com/llvm/llvm-project/pull/229357
More information about the llvm-branch-commits
mailing list