Skip to content

AMDGPU: Make fma_legacy intrinsic propagate poison #131063

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 14, 2025

Conversation

arsenm
Copy link
Contributor

@arsenm arsenm commented Mar 13, 2025

No description provided.

Copy link
Contributor Author

arsenm commented Mar 13, 2025

@arsenm arsenm added backend:AMDGPU llvm:instcombine Covers the InstCombine, InstSimplify and AggressiveInstCombine passes llvm:transforms labels Mar 13, 2025 — with Graphite App
@arsenm arsenm marked this pull request as ready for review March 13, 2025 03:49
@llvmbot
Copy link
Member

llvmbot commented Mar 13, 2025

@llvm/pr-subscribers-llvm-transforms

@llvm/pr-subscribers-backend-amdgpu

Author: Matt Arsenault (arsenm)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/131063.diff

2 Files Affected:

  • (modified) llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp (+5)
  • (modified) llvm/test/Transforms/InstCombine/AMDGPU/fma_legacy.ll (+24)
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)

@arsenm arsenm force-pushed the users/arsenm/amdgpu/propagate-poison-fmul-legacy branch from 5f4a37d to cd3c53b Compare March 14, 2025 01:21
@arsenm arsenm force-pushed the users/arsenm/amdgpu/propagate-poison-fma-legacy branch from 6c1b91a to 45508d8 Compare March 14, 2025 01:21
Copy link
Contributor Author

arsenm commented Mar 14, 2025

Merge activity

  • Mar 14, 12:23 AM EDT: A user started a stack merge that includes this pull request via Graphite.
  • Mar 14, 12:40 AM EDT: Graphite rebased this pull request as part of a merge.
  • Mar 14, 12:42 AM EDT: A user merged this pull request with Graphite.

@arsenm arsenm force-pushed the users/arsenm/amdgpu/propagate-poison-fmul-legacy branch from cd3c53b to ebc436a Compare March 14, 2025 04:36
Base automatically changed from users/arsenm/amdgpu/propagate-poison-fmul-legacy to main March 14, 2025 04:39
@arsenm arsenm force-pushed the users/arsenm/amdgpu/propagate-poison-fma-legacy branch from 45508d8 to 91e5d67 Compare March 14, 2025 04:40
@arsenm arsenm merged commit 4a3ee4f into main Mar 14, 2025
6 of 10 checks passed
@arsenm arsenm deleted the users/arsenm/amdgpu/propagate-poison-fma-legacy branch March 14, 2025 04:42
frederik-h pushed a commit to frederik-h/llvm-project that referenced this pull request Mar 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:AMDGPU llvm:instcombine Covers the InstCombine, InstSimplify and AggressiveInstCombine passes llvm:transforms
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants