Skip to content

AMDGPU: Make fmul_legacy intrinsic propagate poison #131062

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.

@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
Copy link
Contributor Author

arsenm commented Mar 13, 2025

@llvmbot
Copy link
Member

llvmbot commented Mar 13, 2025

@llvm/pr-subscribers-backend-amdgpu

Author: Matt Arsenault (arsenm)

Changes

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

2 Files Affected:

  • (modified) llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp (+5)
  • (modified) llvm/test/Transforms/InstCombine/AMDGPU/fmul_legacy.ll (+16)
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp b/llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp
index 083fa2a730fff..ba4e6e530fe56 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp
@@ -1255,6 +1255,11 @@ GCNTTIImpl::instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const {
     Value *Op0 = II.getArgOperand(0);
     Value *Op1 = II.getArgOperand(1);
 
+    for (Value *Src : {Op0, Op1}) {
+      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/fmul_legacy.ll b/llvm/test/Transforms/InstCombine/AMDGPU/fmul_legacy.ll
index d58470d6b12ad..899b611b929d1 100644
--- a/llvm/test/Transforms/InstCombine/AMDGPU/fmul_legacy.ll
+++ b/llvm/test/Transforms/InstCombine/AMDGPU/fmul_legacy.ll
@@ -75,6 +75,22 @@ define float @test_finite_assumed(float %x, float %y) {
   ret float %call
 }
 
+define float @test_poison_var(float %x) {
+; CHECK-LABEL: @test_poison_var(
+; CHECK-NEXT:    ret float poison
+;
+  %call = call float @llvm.amdgcn.fmul.legacy(float poison, float %x)
+  ret float %call
+}
+
+define float @test_var_poison(float %x) {
+; CHECK-LABEL: @test_var_poison(
+; CHECK-NEXT:    ret float poison
+;
+  %call = call float @llvm.amdgcn.fmul.legacy(float %x, float poison)
+  ret float %call
+}
+
 declare float @llvm.amdgcn.fmul.legacy(float, float)
 declare float @llvm.fabs.f32(float)
 declare void @llvm.assume(i1 noundef)

@llvmbot
Copy link
Member

llvmbot commented Mar 13, 2025

@llvm/pr-subscribers-llvm-transforms

Author: Matt Arsenault (arsenm)

Changes

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

2 Files Affected:

  • (modified) llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp (+5)
  • (modified) llvm/test/Transforms/InstCombine/AMDGPU/fmul_legacy.ll (+16)
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp b/llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp
index 083fa2a730fff..ba4e6e530fe56 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp
@@ -1255,6 +1255,11 @@ GCNTTIImpl::instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const {
     Value *Op0 = II.getArgOperand(0);
     Value *Op1 = II.getArgOperand(1);
 
+    for (Value *Src : {Op0, Op1}) {
+      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/fmul_legacy.ll b/llvm/test/Transforms/InstCombine/AMDGPU/fmul_legacy.ll
index d58470d6b12ad..899b611b929d1 100644
--- a/llvm/test/Transforms/InstCombine/AMDGPU/fmul_legacy.ll
+++ b/llvm/test/Transforms/InstCombine/AMDGPU/fmul_legacy.ll
@@ -75,6 +75,22 @@ define float @test_finite_assumed(float %x, float %y) {
   ret float %call
 }
 
+define float @test_poison_var(float %x) {
+; CHECK-LABEL: @test_poison_var(
+; CHECK-NEXT:    ret float poison
+;
+  %call = call float @llvm.amdgcn.fmul.legacy(float poison, float %x)
+  ret float %call
+}
+
+define float @test_var_poison(float %x) {
+; CHECK-LABEL: @test_var_poison(
+; CHECK-NEXT:    ret float poison
+;
+  %call = call float @llvm.amdgcn.fmul.legacy(float %x, float poison)
+  ret float %call
+}
+
 declare float @llvm.amdgcn.fmul.legacy(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-ballot branch from 3d22d1c to be3d513 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:37 AM EDT: Graphite rebased this pull request as part of a merge.
  • Mar 14, 12:39 AM EDT: A user merged this pull request with Graphite.

@arsenm arsenm force-pushed the users/arsenm/amdgpu/propagate-poison-ballot branch 2 times, most recently from 909bb78 to 3d94386 Compare March 14, 2025 04:33
Base automatically changed from users/arsenm/amdgpu/propagate-poison-ballot to main March 14, 2025 04:36
@arsenm arsenm force-pushed the users/arsenm/amdgpu/propagate-poison-fmul-legacy branch from cd3c53b to ebc436a Compare March 14, 2025 04:36
@arsenm arsenm merged commit 3770689 into main Mar 14, 2025
5 of 10 checks passed
@arsenm arsenm deleted the users/arsenm/amdgpu/propagate-poison-fmul-legacy branch March 14, 2025 04:39
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