[llvm] [DAG] SelectionDAG::canCreateUndefOrPoison - add ISD::FMA/FMAD + tests (PR #152187)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 5 11:22:03 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-selectiondag
Author: None (Seraphimt)
<details>
<summary>Changes</summary>
In SelectionDAG::canCreateUndefOrPoison add case ISD::FMA/FMAD + tests. Fixing #<!-- -->147693
---
Full diff: https://github.com/llvm/llvm-project/pull/152187.diff
2 Files Affected:
- (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (+2)
- (added) llvm/test/CodeGen/AArch64/fma-fneg-combine.ll (+49)
``````````diff
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 61f114411cd0d..3411b035fd409 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -5622,6 +5622,8 @@ bool SelectionDAG::canCreateUndefOrPoison(SDValue Op, const APInt &DemandedElts,
case ISD::FDIV:
case ISD::FREM:
case ISD::FCOPYSIGN:
+ case ISD::FMA:
+ case ISD::FMAD:
// No poison except from flags (which is handled above)
return false;
diff --git a/llvm/test/CodeGen/AArch64/fma-fneg-combine.ll b/llvm/test/CodeGen/AArch64/fma-fneg-combine.ll
new file mode 100644
index 0000000000000..c72795f9f5d71
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/fma-fneg-combine.ll
@@ -0,0 +1,49 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
+; RUN: llc < %s -mtriple=aarch64-- | FileCheck %s --check-prefixes=CHECK
+
+define float @positive_case_fma(float %a0, float %a1, float %a2) {
+; CHECK-LABEL: positive_case_fma:
+; CHECK: // %bb.0:
+; CHECK-NEXT: fnmadd s0, s0, s1, s2
+; CHECK-NEXT: ret
+ %fma = call float @llvm.fma.f32(float %a0, float %a1, float %a2)
+ %freeze = freeze float %fma
+ %fneg = fneg float %freeze
+ ret float %fneg
+}
+
+define float @negative_case_fma(float %a0, float %a1) {
+; CHECK-LABEL: negative_case_fma:
+; CHECK: // %bb.0:
+; CHECK-NEXT: fnmadd s0, s0, s1, s0
+; CHECK-NEXT: ret
+ %fma = call float @llvm.fma.f32(float %a0, float %a1, float poison)
+ %freeze = freeze float %fma
+ %fneg = fneg float %freeze
+ ret float %fneg
+}
+
+define float @positive_case_fmad(float %a0, float %a1, float %a2) {
+; CHECK-LABEL: positive_case_fmad:
+; CHECK: // %bb.0:
+; CHECK-NEXT: fnmadd s0, s0, s1, s2
+; CHECK-NEXT: ret
+ %fma = call float @llvm.fma.f32(float %a0, float %a1, float %a2)
+ %freeze = freeze float %fma
+ %fneg = fneg float %freeze
+ ret float %fneg
+}
+
+define float @negative_case_fmad(float %a0, float %a1) {
+; CHECK-LABEL: negative_case_fmad:
+; CHECK: // %bb.0:
+; CHECK-NEXT: fnmadd s0, s0, s1, s0
+; CHECK-NEXT: ret
+ %fmad = call float @llvm.fmuladd.f32(float %a0, float %a1, float poison)
+ %freeze = freeze float %fmad
+ %fneg = fneg float %freeze
+ ret float %fneg
+}
+
+
+
``````````
</details>
https://github.com/llvm/llvm-project/pull/152187
More information about the llvm-commits
mailing list