[llvm-branch-commits] [llvm] AMDGPU: Make fma_legacy intrinsic propagate poison (PR #131063)

Matt Arsenault via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Mar 12 20:49:24 PDT 2025


https://github.com/arsenm created https://github.com/llvm/llvm-project/pull/131063

None

>From 6c1b91af15a9384f9999ba72f78b549b97893fb7 Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Thu, 13 Mar 2025 10:48:15 +0700
Subject: [PATCH] AMDGPU: Make fma_legacy intrinsic propagate poison

---
 .../AMDGPU/AMDGPUInstCombineIntrinsic.cpp     |  5 ++++
 .../InstCombine/AMDGPU/fma_legacy.ll          | 24 +++++++++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp b/llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp
index ba4e6e530fe56..86f33f33d1fc7 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp
@@ -1281,6 +1281,11 @@ GCNTTIImpl::instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const {
     Value *Op1 = II.getArgOperand(1);
     Value *Op2 = II.getArgOperand(2);
 
+    for (Value *Src : {Op0, Op1, Op2}) {
+      if (isa<PoisonValue>(Src))
+        return IC.replaceInstUsesWith(II, Src);
+    }
+
     // The legacy behaviour is that multiplying +/-0.0 by anything, even NaN or
     // infinity, gives +0.0.
     // TODO: Move to InstSimplify?
diff --git a/llvm/test/Transforms/InstCombine/AMDGPU/fma_legacy.ll b/llvm/test/Transforms/InstCombine/AMDGPU/fma_legacy.ll
index 72bffe62fbb14..b2f851d6d56ed 100644
--- a/llvm/test/Transforms/InstCombine/AMDGPU/fma_legacy.ll
+++ b/llvm/test/Transforms/InstCombine/AMDGPU/fma_legacy.ll
@@ -105,6 +105,30 @@ define float @test_finite_assumed(float %x, float %y, float %z) {
   ret float %call
 }
 
+define float @test_poison_x_y(float %x, float %y) {
+; CHECK-LABEL: @test_poison_x_y(
+; CHECK-NEXT:    ret float poison
+;
+  %call = call float @llvm.amdgcn.fma.legacy(float poison, float %x, float %y)
+  ret float %call
+}
+
+define float @test_x_poison_y(float %x, float %y) {
+; CHECK-LABEL: @test_x_poison_y(
+; CHECK-NEXT:    ret float poison
+;
+  %call = call float @llvm.amdgcn.fma.legacy(float %x, float poison, float %y)
+  ret float %call
+}
+
+define float @test_x_y_poison_y(float %x, float %y) {
+; CHECK-LABEL: @test_x_y_poison_y(
+; CHECK-NEXT:    ret float poison
+;
+  %call = call float @llvm.amdgcn.fma.legacy(float %x, float %y, float poison)
+  ret float %call
+}
+
 declare float @llvm.amdgcn.fma.legacy(float, float, float)
 declare float @llvm.fabs.f32(float)
 declare void @llvm.assume(i1 noundef)



More information about the llvm-branch-commits mailing list