[llvm] [AMDGPU] Avoid fract fold when result is observable at +/-inf (PR #219515)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 28 09:26:19 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-amdgpu
Author: Arseniy Obolenskiy (aobolensk)
<details>
<summary>Changes</summary>
fract returns nan at +/-inf, while minnum/minimumnum clamp to the constant there, so the fold is only safe when that difference can't be observed
---
Patch is 111.00 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/219515.diff
2 Files Affected:
- (modified) llvm/lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp (+79-6)
- (modified) llvm/test/CodeGen/AMDGPU/fract-match.ll (+1112-424)
``````````diff
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp b/llvm/lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp
index 21a8896ed3a6d..e5e353e8d55ee 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp
@@ -19,6 +19,7 @@
#include "llvm/ADT/SetVector.h"
#include "llvm/Analysis/AssumptionCache.h"
#include "llvm/Analysis/ConstantFolding.h"
+#include "llvm/Analysis/FloatingPointPredicateUtils.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/Analysis/UniformityAnalysis.h"
@@ -213,7 +214,11 @@ class AMDGPUCodeGenPrepareImpl
bool canWidenScalarExtLoad(LoadInst &I) const;
Value *matchFractPatImpl(Value &V, const APFloat &C) const;
- Value *matchFractPatNanAvoidant(Value &V);
+ Value *matchFractPatNanAvoidant(Value &V,
+ Instruction *RootToReplace = nullptr);
+ bool isFractNanAvoidantFoldLegalAtInf(const IntrinsicInst *MinI,
+ const Value *Sub, const Value *X,
+ Instruction *Root) const;
Value *applyFractPat(IRBuilder<> &Builder, Value *FractArg);
bool canOptimizeWithRsq(FastMathFlags DivFMF, FastMathFlags SqrtFMF) const;
@@ -1619,11 +1624,11 @@ bool AMDGPUCodeGenPrepareImpl::visitSelectInst(SelectInst &I) {
Builder.setFastMathFlags(FPOp->getFastMathFlags());
if (IsNanPred == FCmpInst::FCMP_UNO && TrueVal == CmpVal &&
- CmpVal == matchFractPatNanAvoidant(*FalseVal)) {
+ CmpVal == matchFractPatNanAvoidant(*FalseVal, &I)) {
// isnan(x) ? x : fract(x)
Fract = applyFractPat(Builder, CmpVal);
} else if (IsNanPred == FCmpInst::FCMP_ORD && FalseVal == CmpVal) {
- if (CmpVal == matchFractPatNanAvoidant(*TrueVal)) {
+ if (CmpVal == matchFractPatNanAvoidant(*TrueVal, &I)) {
// !isnan(x) ? fract(x) : x
Fract = applyFractPat(Builder, CmpVal);
} else {
@@ -2100,7 +2105,11 @@ Value *AMDGPUCodeGenPrepareImpl::matchFractPatImpl(Value &FractSrc,
///
/// If fract is a useful instruction for the subtarget. Does not account for the
/// nan handling; the instruction has a nan check on the input value.
-Value *AMDGPUCodeGenPrepareImpl::matchFractPatNanAvoidant(Value &V) {
+///
+/// If \p RootToReplace is set, the fract must also be unobservable at +/-inf.
+Value *
+AMDGPUCodeGenPrepareImpl::matchFractPatNanAvoidant(Value &V,
+ Instruction *RootToReplace) {
Value *Arg0;
const APFloat *C;
@@ -2112,7 +2121,71 @@ Value *AMDGPUCodeGenPrepareImpl::matchFractPatNanAvoidant(Value &V) {
m_FMinimum(m_Value(Arg0), m_APFloatAllowPoison(C)))))
return nullptr;
- return matchFractPatImpl(*Arg0, *C);
+ Value *FractArg = matchFractPatImpl(*Arg0, *C);
+ if (!FractArg)
+ return nullptr;
+
+ if (RootToReplace &&
+ !isFractNanAvoidantFoldLegalAtInf(cast<IntrinsicInst>(&V), Arg0, FractArg,
+ RootToReplace))
+ return nullptr;
+
+ return FractArg;
+}
+
+/// True if \p U is a select that never picks \p V when \p X is infinity, e.g.
+/// fract's library inf-clamp: select (fcmp oeq (fabs X), +inf), 0.0, V
+static bool isInfDiscardingSelect(User *U, const Value *X, const Value *V) {
+ auto *Sel = dyn_cast<SelectInst>(U);
+ if (!Sel)
+ return false;
+
+ bool IsTrueArm = Sel->getTrueValue() == V;
+ if (!IsTrueArm && Sel->getFalseValue() != V)
+ return false;
+ if (IsTrueArm && Sel->getFalseValue() == V)
+ return false;
+
+ auto *Cmp = dyn_cast<FCmpInst>(Sel->getCondition());
+ if (!Cmp)
+ return false;
+
+ auto [ClassVal, ClassesIfTrue, ClassesIfFalse] =
+ fcmpImpliesClass(Cmp->getPredicate(), *Sel->getFunction(),
+ Cmp->getOperand(0), Cmp->getOperand(1));
+ if (ClassVal != X)
+ return false;
+
+ return !((IsTrueArm ? ClassesIfTrue : ClassesIfFalse) & fcInf);
+}
+
+/// At +/-inf \p Sub is nan, so \p MinI clamps while fract would return nan;
+/// true if replacing \p Root with fract of \p X is unobservable there. Callers
+/// must not pass a \p Root that can select around \p MinI at +/-inf, since the
+/// poison cases assume \p Root is poison whenever \p MinI is.
+bool AMDGPUCodeGenPrepareImpl::isFractNanAvoidantFoldLegalAtInf(
+ const IntrinsicInst *MinI, const Value *Sub, const Value *X,
+ Instruction *Root) const {
+ // minimum propagates the nan from x - floor(x), exactly like fract.
+ if (MinI->getIntrinsicID() == Intrinsic::minimum)
+ return true;
+
+ // nnan poisons the min at +/-inf; ninf proves nothing here.
+ if (MinI->hasNoNaNs())
+ return true;
+
+ // At +/-inf the fsub is nan with infinite operands, so nnan/ninf poison it.
+ const auto *FPSub = cast<FPMathOperator>(Sub);
+ if (FPSub->hasNoNaNs() || FPSub->hasNoInfs())
+ return true;
+
+ // The result is only observed where an explicit infinity check discards it:
+ // isinf(x) ? 0.0 : (isnan(x) ? x : minnum(x - floor(x), C))
+ if (all_of(Root->users(),
+ [=](User *U) { return isInfDiscardingSelect(U, X, Root); }))
+ return true;
+
+ return isKnownNeverInfinity(X, SQ.getWithInstruction(Root));
}
Value *AMDGPUCodeGenPrepareImpl::applyFractPat(IRBuilder<> &Builder,
@@ -2144,7 +2217,7 @@ bool AMDGPUCodeGenPrepareImpl::visitFMinLike(IntrinsicInst &I) {
return false;
} else {
// minnum(x - floor(x), MIN_CONSTANT)
- FractArg = matchFractPatNanAvoidant(I);
+ FractArg = matchFractPatNanAvoidant(I, &I);
if (!FractArg)
return false;
diff --git a/llvm/test/CodeGen/AMDGPU/fract-match.ll b/llvm/test/CodeGen/AMDGPU/fract-match.ll
index b40763b4ca5f4..b2dfb24b1eacb 100644
--- a/llvm/test/CodeGen/AMDGPU/fract-match.ll
+++ b/llvm/test/CodeGen/AMDGPU/fract-match.ll
@@ -523,24 +523,16 @@ entry:
}
define float @safe_math_fract_f32_noinf_check(float %x, ptr addrspace(1) writeonly captures(none) %ip) {
-; GFX6-IR-LABEL: define float @safe_math_fract_f32_noinf_check(
-; GFX6-IR-SAME: float [[X:%.*]], ptr addrspace(1) writeonly captures(none) [[IP:%.*]]) {
-; GFX6-IR-NEXT: [[ENTRY:.*:]]
-; GFX6-IR-NEXT: [[FLOOR:%.*]] = tail call float @llvm.floor.f32(float [[X]])
-; GFX6-IR-NEXT: [[SUB:%.*]] = fsub float [[X]], [[FLOOR]]
-; GFX6-IR-NEXT: [[MIN:%.*]] = tail call float @llvm.minnum.f32(float [[SUB]], float f0x3F7FFFFF)
-; GFX6-IR-NEXT: [[UNO:%.*]] = fcmp uno float [[X]], 0.000000e+00
-; GFX6-IR-NEXT: [[COND:%.*]] = select i1 [[UNO]], float [[X]], float [[MIN]]
-; GFX6-IR-NEXT: store float [[FLOOR]], ptr addrspace(1) [[IP]], align 4
-; GFX6-IR-NEXT: ret float [[COND]]
-;
-; IR-FRACT-LABEL: define float @safe_math_fract_f32_noinf_check(
-; IR-FRACT-SAME: float [[X:%.*]], ptr addrspace(1) writeonly captures(none) [[IP:%.*]]) {
-; IR-FRACT-NEXT: [[ENTRY:.*:]]
-; IR-FRACT-NEXT: [[FLOOR:%.*]] = tail call float @llvm.floor.f32(float [[X]])
-; IR-FRACT-NEXT: [[COND:%.*]] = call float @llvm.amdgcn.fract.f32(float [[X]])
-; IR-FRACT-NEXT: store float [[FLOOR]], ptr addrspace(1) [[IP]], align 4
-; IR-FRACT-NEXT: ret float [[COND]]
+; IR-LABEL: define float @safe_math_fract_f32_noinf_check(
+; IR-SAME: float [[X:%.*]], ptr addrspace(1) writeonly captures(none) [[IP:%.*]]) {
+; IR-NEXT: [[ENTRY:.*:]]
+; IR-NEXT: [[FLOOR:%.*]] = tail call float @llvm.floor.f32(float [[X]])
+; IR-NEXT: [[SUB:%.*]] = fsub float [[X]], [[FLOOR]]
+; IR-NEXT: [[MIN:%.*]] = tail call float @llvm.minnum.f32(float [[SUB]], float f0x3F7FFFFF)
+; IR-NEXT: [[UNO:%.*]] = fcmp uno float [[X]], 0.000000e+00
+; IR-NEXT: [[COND:%.*]] = select i1 [[UNO]], float [[X]], float [[MIN]]
+; IR-NEXT: store float [[FLOOR]], ptr addrspace(1) [[IP]], align 4
+; IR-NEXT: ret float [[COND]]
;
; GFX6-LABEL: safe_math_fract_f32_noinf_check:
; GFX6: ; %bb.0: ; %entry
@@ -557,33 +549,47 @@ define float @safe_math_fract_f32_noinf_check(float %x, ptr addrspace(1) writeon
; GFX6-NEXT: buffer_store_dword v3, v[1:2], s[4:7], 0 addr64
; GFX6-NEXT: s_waitcnt vmcnt(0) expcnt(0)
; GFX6-NEXT: s_setpc_b64 s[30:31]
+;
; GFX7-LABEL: safe_math_fract_f32_noinf_check:
; GFX7: ; %bb.0: ; %entry
; GFX7-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
+; GFX7-NEXT: v_floor_f32_e32 v3, v0
+; GFX7-NEXT: v_sub_f32_e32 v4, v0, v3
; GFX7-NEXT: s_mov_b32 s6, 0
+; GFX7-NEXT: v_min_f32_e32 v4, 0x3f7fffff, v4
+; GFX7-NEXT: v_cmp_u_f32_e32 vcc, v0, v0
; GFX7-NEXT: s_mov_b32 s7, 0xf000
; GFX7-NEXT: s_mov_b32 s4, s6
; GFX7-NEXT: s_mov_b32 s5, s6
-; GFX7-NEXT: v_floor_f32_e32 v3, v0
-; GFX7-NEXT: v_fract_f32_e32 v0, v0
+; GFX7-NEXT: v_cndmask_b32_e32 v0, v4, v0, vcc
; GFX7-NEXT: buffer_store_dword v3, v[1:2], s[4:7], 0 addr64
; GFX7-NEXT: s_waitcnt vmcnt(0)
; GFX7-NEXT: s_setpc_b64 s[30:31]
+;
; GFX8-LABEL: safe_math_fract_f32_noinf_check:
; GFX8: ; %bb.0: ; %entry
; GFX8-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
; GFX8-NEXT: v_floor_f32_e32 v3, v0
-; GFX8-NEXT: v_fract_f32_e32 v0, v0
+; GFX8-NEXT: v_sub_f32_e32 v4, v0, v3
+; GFX8-NEXT: v_min_f32_e32 v4, 0x3f7fffff, v4
+; GFX8-NEXT: v_cmp_u_f32_e32 vcc, v0, v0
+; GFX8-NEXT: v_cndmask_b32_e32 v0, v4, v0, vcc
; GFX8-NEXT: global_store_dword v[1:2], v3, off
; GFX8-NEXT: s_waitcnt vmcnt(0)
; GFX8-NEXT: s_setpc_b64 s[30:31]
+;
; GFX11-LABEL: safe_math_fract_f32_noinf_check:
; GFX11: ; %bb.0: ; %entry
; GFX11-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
; GFX11-NEXT: v_floor_f32_e32 v3, v0
-; GFX11-NEXT: v_fract_f32_e32 v0, v0
+; GFX11-NEXT: v_cmp_u_f32_e32 vcc_lo, v0, v0
+; GFX11-NEXT: s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_2) | instid1(VALU_DEP_1)
+; GFX11-NEXT: v_sub_f32_e32 v4, v0, v3
; GFX11-NEXT: global_store_b32 v[1:2], v3, off
+; GFX11-NEXT: v_min_f32_e32 v4, 0x3f7fffff, v4
+; GFX11-NEXT: v_cndmask_b32_e32 v0, v4, v0, vcc_lo
; GFX11-NEXT: s_setpc_b64 s[30:31]
+;
; GFX12-LABEL: safe_math_fract_f32_noinf_check:
; GFX12: ; %bb.0: ; %entry
; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0
@@ -592,8 +598,13 @@ define float @safe_math_fract_f32_noinf_check(float %x, ptr addrspace(1) writeon
; GFX12-NEXT: s_wait_bvhcnt 0x0
; GFX12-NEXT: s_wait_kmcnt 0x0
; GFX12-NEXT: v_floor_f32_e32 v3, v0
-; GFX12-NEXT: v_fract_f32_e32 v0, v0
+; GFX12-NEXT: v_cmp_u_f32_e32 vcc_lo, v0, v0
+; GFX12-NEXT: s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_3) | instid1(VALU_DEP_1)
+; GFX12-NEXT: v_sub_f32_e32 v4, v0, v3
; GFX12-NEXT: global_store_b32 v[1:2], v3, off
+; GFX12-NEXT: v_min_num_f32_e32 v4, 0x3f7fffff, v4
+; GFX12-NEXT: s_wait_alu depctr_va_vcc(0)
+; GFX12-NEXT: v_cndmask_b32_e32 v0, v4, v0, vcc_lo
; GFX12-NEXT: s_setpc_b64 s[30:31]
entry:
%floor = tail call float @llvm.floor.f32(float %x)
@@ -702,19 +713,13 @@ entry:
}
define float @basic_fract_f32_nonans(float nofpclass(nan) %x) {
-; GFX6-IR-LABEL: define float @basic_fract_f32_nonans(
-; GFX6-IR-SAME: float nofpclass(nan) [[X:%.*]]) {
-; GFX6-IR-NEXT: [[ENTRY:.*:]]
-; GFX6-IR-NEXT: [[FLOOR:%.*]] = tail call float @llvm.floor.f32(float [[X]])
-; GFX6-IR-NEXT: [[SUB:%.*]] = fsub float [[X]], [[FLOOR]]
-; GFX6-IR-NEXT: [[MIN:%.*]] = tail call float @llvm.minnum.f32(float [[SUB]], float f0x3F7FFFFF)
-; GFX6-IR-NEXT: ret float [[MIN]]
-;
-; IR-FRACT-LABEL: define float @basic_fract_f32_nonans(
-; IR-FRACT-SAME: float nofpclass(nan) [[X:%.*]]) {
-; IR-FRACT-NEXT: [[ENTRY:.*:]]
-; IR-FRACT-NEXT: [[MIN:%.*]] = call nnan float @llvm.amdgcn.fract.f32(float [[X]])
-; IR-FRACT-NEXT: ret float [[MIN]]
+; IR-LABEL: define float @basic_fract_f32_nonans(
+; IR-SAME: float nofpclass(nan) [[X:%.*]]) {
+; IR-NEXT: [[ENTRY:.*:]]
+; IR-NEXT: [[FLOOR:%.*]] = tail call float @llvm.floor.f32(float [[X]])
+; IR-NEXT: [[SUB:%.*]] = fsub float [[X]], [[FLOOR]]
+; IR-NEXT: [[MIN:%.*]] = tail call float @llvm.minnum.f32(float [[SUB]], float f0x3F7FFFFF)
+; IR-NEXT: ret float [[MIN]]
;
; GFX6-LABEL: basic_fract_f32_nonans:
; GFX6: ; %bb.0: ; %entry
@@ -723,21 +728,32 @@ define float @basic_fract_f32_nonans(float nofpclass(nan) %x) {
; GFX6-NEXT: v_sub_f32_e32 v0, v0, v1
; GFX6-NEXT: v_min_f32_e32 v0, 0x3f7fffff, v0
; GFX6-NEXT: s_setpc_b64 s[30:31]
+;
; GFX7-LABEL: basic_fract_f32_nonans:
; GFX7: ; %bb.0: ; %entry
; GFX7-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
-; GFX7-NEXT: v_fract_f32_e32 v0, v0
+; GFX7-NEXT: v_floor_f32_e32 v1, v0
+; GFX7-NEXT: v_sub_f32_e32 v0, v0, v1
+; GFX7-NEXT: v_min_f32_e32 v0, 0x3f7fffff, v0
; GFX7-NEXT: s_setpc_b64 s[30:31]
+;
; GFX8-LABEL: basic_fract_f32_nonans:
; GFX8: ; %bb.0: ; %entry
; GFX8-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
-; GFX8-NEXT: v_fract_f32_e32 v0, v0
+; GFX8-NEXT: v_floor_f32_e32 v1, v0
+; GFX8-NEXT: v_sub_f32_e32 v0, v0, v1
+; GFX8-NEXT: v_min_f32_e32 v0, 0x3f7fffff, v0
; GFX8-NEXT: s_setpc_b64 s[30:31]
+;
; GFX11-LABEL: basic_fract_f32_nonans:
; GFX11: ; %bb.0: ; %entry
; GFX11-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
-; GFX11-NEXT: v_fract_f32_e32 v0, v0
+; GFX11-NEXT: v_floor_f32_e32 v1, v0
+; GFX11-NEXT: s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
+; GFX11-NEXT: v_sub_f32_e32 v0, v0, v1
+; GFX11-NEXT: v_min_f32_e32 v0, 0x3f7fffff, v0
; GFX11-NEXT: s_setpc_b64 s[30:31]
+;
; GFX12-LABEL: basic_fract_f32_nonans:
; GFX12: ; %bb.0: ; %entry
; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0
@@ -745,7 +761,10 @@ define float @basic_fract_f32_nonans(float nofpclass(nan) %x) {
; GFX12-NEXT: s_wait_samplecnt 0x0
; GFX12-NEXT: s_wait_bvhcnt 0x0
; GFX12-NEXT: s_wait_kmcnt 0x0
-; GFX12-NEXT: v_fract_f32_e32 v0, v0
+; GFX12-NEXT: v_floor_f32_e32 v1, v0
+; GFX12-NEXT: s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
+; GFX12-NEXT: v_sub_f32_e32 v0, v0, v1
+; GFX12-NEXT: v_min_num_f32_e32 v0, 0x3f7fffff, v0
; GFX12-NEXT: s_setpc_b64 s[30:31]
entry:
%floor = tail call float @llvm.floor.f32(float %x)
@@ -812,19 +831,13 @@ entry:
}
define float @basic_fract_f32_flags_fsub(float nofpclass(nan) %x) {
-; GFX6-IR-LABEL: define float @basic_fract_f32_flags_fsub(
-; GFX6-IR-SAME: float nofpclass(nan) [[X:%.*]]) {
-; GFX6-IR-NEXT: [[ENTRY:.*:]]
-; GFX6-IR-NEXT: [[FLOOR:%.*]] = tail call float @llvm.floor.f32(float [[X]])
-; GFX6-IR-NEXT: [[SUB:%.*]] = fsub nsz float [[X]], [[FLOOR]]
-; GFX6-IR-NEXT: [[MIN:%.*]] = tail call float @llvm.minnum.f32(float [[SUB]], float f0x3F7FFFFF)
-; GFX6-IR-NEXT: ret float [[MIN]]
-;
-; IR-FRACT-LABEL: define float @basic_fract_f32_flags_fsub(
-; IR-FRACT-SAME: float nofpclass(nan) [[X:%.*]]) {
-; IR-FRACT-NEXT: [[ENTRY:.*:]]
-; IR-FRACT-NEXT: [[MIN:%.*]] = call nnan float @llvm.amdgcn.fract.f32(float [[X]])
-; IR-FRACT-NEXT: ret float [[MIN]]
+; IR-LABEL: define float @basic_fract_f32_flags_fsub(
+; IR-SAME: float nofpclass(nan) [[X:%.*]]) {
+; IR-NEXT: [[ENTRY:.*:]]
+; IR-NEXT: [[FLOOR:%.*]] = tail call float @llvm.floor.f32(float [[X]])
+; IR-NEXT: [[SUB:%.*]] = fsub nsz float [[X]], [[FLOOR]]
+; IR-NEXT: [[MIN:%.*]] = tail call float @llvm.minnum.f32(float [[SUB]], float f0x3F7FFFFF)
+; IR-NEXT: ret float [[MIN]]
;
; GFX6-LABEL: basic_fract_f32_flags_fsub:
; GFX6: ; %bb.0: ; %entry
@@ -833,21 +846,32 @@ define float @basic_fract_f32_flags_fsub(float nofpclass(nan) %x) {
; GFX6-NEXT: v_sub_f32_e32 v0, v0, v1
; GFX6-NEXT: v_min_f32_e32 v0, 0x3f7fffff, v0
; GFX6-NEXT: s_setpc_b64 s[30:31]
+;
; GFX7-LABEL: basic_fract_f32_flags_fsub:
; GFX7: ; %bb.0: ; %entry
; GFX7-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
-; GFX7-NEXT: v_fract_f32_e32 v0, v0
+; GFX7-NEXT: v_floor_f32_e32 v1, v0
+; GFX7-NEXT: v_sub_f32_e32 v0, v0, v1
+; GFX7-NEXT: v_min_f32_e32 v0, 0x3f7fffff, v0
; GFX7-NEXT: s_setpc_b64 s[30:31]
+;
; GFX8-LABEL: basic_fract_f32_flags_fsub:
; GFX8: ; %bb.0: ; %entry
; GFX8-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
-; GFX8-NEXT: v_fract_f32_e32 v0, v0
+; GFX8-NEXT: v_floor_f32_e32 v1, v0
+; GFX8-NEXT: v_sub_f32_e32 v0, v0, v1
+; GFX8-NEXT: v_min_f32_e32 v0, 0x3f7fffff, v0
; GFX8-NEXT: s_setpc_b64 s[30:31]
+;
; GFX11-LABEL: basic_fract_f32_flags_fsub:
; GFX11: ; %bb.0: ; %entry
; GFX11-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
-; GFX11-NEXT: v_fract_f32_e32 v0, v0
+; GFX11-NEXT: v_floor_f32_e32 v1, v0
+; GFX11-NEXT: s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
+; GFX11-NEXT: v_sub_f32_e32 v0, v0, v1
+; GFX11-NEXT: v_min_f32_e32 v0, 0x3f7fffff, v0
; GFX11-NEXT: s_setpc_b64 s[30:31]
+;
; GFX12-LABEL: basic_fract_f32_flags_fsub:
; GFX12: ; %bb.0: ; %entry
; GFX12-NEXT: s_wait_loadcnt_dscnt 0x0
@@ -855,7 +879,10 @@ define float @basic_fract_f32_flags_fsub(float nofpclass(nan) %x) {
; GFX12-NEXT: s_wait_samplecnt 0x0
; GFX12-NEXT: s_wait_bvhcnt 0x0
; GFX12-NEXT: s_wait_kmcnt 0x0
-; GFX12-NEXT: v_fract_f32_e32 v0, v0
+; GFX12-NEXT: v_floor_f32_e32 v1, v0
+; GFX12-NEXT: s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
+; GFX12-NEXT: v_sub_f32_e32 v0, v0, v1
+; GFX12-NEXT: v_min_num_f32_e32 v0, 0x3f7fffff, v0
; GFX12-NEXT: s_setpc_b64 s[30:31]
entry:
%floor = tail call float @llvm.floor.f32(float %x)
@@ -865,24 +892,13 @@ entry:
}
define <2 x float> @basic_fract_v2f32_nonans(<2 x float> nofpclass(nan) %x) {
-; GFX6-IR-LABEL: define <2 x float> @basic_fract_v2f32_nonans(
-; GFX6-IR-SAME: <2 x float> nofpclass(nan) [[X:%.*]]) {
-; GFX6-IR-NEXT: [[ENTRY:.*:]]
-; GFX6-IR-NEXT: [[FLOOR:%.*]] = tail call <2 x float> @llvm.floor.v2f32(<2 x float> [[X]])
-; GFX6-IR-NEXT: [[SUB:%.*]] = fsub <2 x float> [[X]], [[FLOOR]]
-; GFX6-IR-NEXT: [[MIN:%.*]] = tail call <2 x float> @llvm.minnum.v2f32(<2 x float> [[SUB]], <2 x float> splat (float f0x3F7FFFFF))
-; GFX6-IR-NEXT: ret <2 x float> [[MIN]]
-;
-; IR-FRACT-LABEL: define <2 x float> @basic_fract_v2f32_nonans(
-; IR-FRACT-SAME: <2 x float> nofpclass(nan) [[X:%.*]]) {
-; IR-FRACT-NEXT: [[ENTRY:.*:]]
-; IR-FRACT-NEXT: [[TMP0:%.*]] = extractelement <2 x float> [[X]], i64 0
-; IR-FRACT-NEXT: [[TMP1:%.*]] = extractelement <2 x float> [[X]], i64 1
-; IR-FRACT-NEXT: [[TMP2:%.*]] = call nnan float @llvm.amdgcn.fract.f32(float [[TMP0]])
-; IR-FRACT-NEXT: [[TMP3:%.*]] = call nnan float @llvm.amdgcn.fract.f32(float [[TMP1]])
-; IR-FRACT-NEXT: [[TMP4:%.*]] = insertelement <2 x float> poison, float [[TMP2]], i64 0
-; IR-FRACT-NEXT: [[MIN:%.*]] = insertelement <2 x float> [[TMP4]], float [[TMP3]], i64 1
-; IR-FRACT-NEXT: ret <2 x float> [[MIN]]
+; IR-LABEL: define <2 x float> @basic_fract_v2f32_nonans(
+; IR-SAME: <2 x float> nofpclass(nan) [[X:%.*]]) {
+; IR-NEXT: [[ENTRY:.*:]]
+; IR-NEXT: [[FLOOR:%.*]] = tail call <2 x float> @llvm.floor.v2f32(<2 x float> [[X]])
+; IR-NEXT: [[SUB:%.*]] = fsub <2 x float> [[X]], [[FLOOR]]
+; IR-NEXT: [[MIN:%.*]] = tail call <2 x float> @llvm.minnum.v2f32(<2 x float> [[SUB]], <2 x float> splat (float f0x3F7FFFFF))
+; IR-NEXT: ret <2 x float> [[MIN]]
;
; GFX6-LABEL: basic_fract_v2f32_nonans:
; GFX6: ; %bb.0: ; %entry
@@ -894,24 +910,39 @@ define <2 x float> @basic_fract_v2f32_nonans(<2 x float> nofpclass(nan) %x) {
; GFX6-NEXT: v_min_f32_e32 v0, 0x3f7fffff, v0
; GFX6-NEXT: v_min_f32_e32 v1, 0x3f7fffff, v1
; GFX6-NEXT: s_setpc_b64 s[30:31]
+;
; GFX7-LABEL: basic_fract_v2f32_nonans:
; GFX7: ; %bb.0: ; %entry
; GFX7-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
-; GFX7-NEXT: v_fract_f32_e32 v0, v0
-; GFX7-NEXT: v_fract_f32_e32 v1, v1
+; GFX7-NEXT: v_floor_f32_e32 v2, v0
+; GFX7-NEXT: v_floor_f32_e32 v3, v1
+; GFX7-NEXT: v_sub_f32_e32 v1, v1, v3
+; GFX7-NEXT: v_sub_f32_e32 v0, v0, v2
+; GFX7-NEXT: v_min_f32_e32 v0, 0x3f7fffff, v0
+; GFX7-NEXT: v_min_f32_e32 v1, 0x3f7fffff, v1
; GFX7-NEXT: s_setpc_b64 s[30:31]
+;
; GFX8-LABEL: basic_fract_v2f32_nonans:
; GFX8: ; %bb.0: ; %entry
; GFX8-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
-; GFX8-NEXT: v_fract_f32_e32 v0, v0
-; GFX8-NEXT: v_fract_f32_e32 v1, v1
+; GFX8-NEXT: v_floor_f32_e32 v2, v0
+; GFX8-NEXT: v_floor_f32_e32 v3, v1
+; GFX8-NEXT: v_sub_f32_e32 v1, v1, v3
+; GFX8-NEXT: v...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/219515
More information about the llvm-commits
mailing list