[llvm] [DAG] canCreateUndefOrPoison – mark fneg/fadd/fsub/fmul/fdiv/frem as not poison generating (PR #142345)
Harrison Hao via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 2 02:08:08 PDT 2025
================
@@ -0,0 +1,282 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
+; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx1100 -verify-machineinstrs < %s | FileCheck %s -check-prefix GFX11
+define float @freeze_fadd(float %input) nounwind {
+; GFX11-LABEL: freeze_fadd:
+; GFX11: ; %bb.0: ; %entry
+; GFX11-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
+; GFX11-NEXT: v_add_f32_e32 v0, 2.0, v0
+; GFX11-NEXT: s_setpc_b64 s[30:31]
+entry:
+ %x = fadd reassoc nsz arcp contract afn float %input, 1.000000e+00
+ %y = freeze float %x
+ %z = fadd reassoc nsz arcp contract afn float %y, 1.000000e+00
+ ret float %z
+}
+
+define float @freeze_fadd_nnan(float %input) nounwind {
+; GFX11-LABEL: freeze_fadd_nnan:
+; GFX11: ; %bb.0: ; %entry
+; GFX11-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
+; GFX11-NEXT: v_add_f32_e32 v0, 1.0, v0
+; GFX11-NEXT: s_delay_alu instid0(VALU_DEP_1)
+; GFX11-NEXT: v_add_f32_e32 v0, 1.0, v0
+; GFX11-NEXT: s_setpc_b64 s[30:31]
+entry:
+ %x = fadd nnan contract float %input, 1.000000e+00
+ %y = freeze float %x
+ %z = fadd nnan contract float %y, 1.000000e+00
----------------
harrisonGPU wrote:
Thanks a lot! Initially, I intended to test the case where `Op->hasPoisonGeneratingFlags()` returns true, so I used the nnan flag as an example:
https://github.com/llvm/llvm-project/blob/e3a0cb8d3f53e6b2d801e2fe732057f94704e6b7/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp#L5578-L5579
However, upon further inspection, I realize this isn't necessary. When we actually call `canCreateUndefOrPoison` in this context, we explicitly set `ConsiderFlags` to false, as shown in the following snippet:
```cpp
if (DAG.canCreateUndefOrPoison(N0, /*PoisonOnly*/ false,
/*ConsiderFlags*/ false) ||
N0->getNumValues() != 1 || !N0->hasOneUse())
return SDValue();
```
Thus, even if I set the `nnan` flag, it won't affect this particular test case. Therefore, I've removed the unnecessary tests involving nnan. Additionally, I previously forgot to include tests for fneg, which I have now added.
What do you think?
https://github.com/llvm/llvm-project/pull/142345
More information about the llvm-commits
mailing list