Skip to content

AMDGPU: Make fmed3 intrinsic propagate poison #131060

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

@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/131060.diff

2 Files Affected:

  • (modified) llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp (+5)
  • (modified) llvm/test/Transforms/InstCombine/AMDGPU/amdgcn-intrinsics.ll (+24)
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp b/llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp
index 75b79b129d358..5d6f6d0c2c901 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp
@@ -826,6 +826,11 @@ GCNTTIImpl::instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const {
     Value *Src1 = II.getArgOperand(1);
     Value *Src2 = II.getArgOperand(2);
 
+    for (Value *Src : {Src0, Src1, Src2}) {
+      if (isa<PoisonValue>(Src))
+        return IC.replaceInstUsesWith(II, Src);
+    }
+
     // Checking for NaN before canonicalization provides better fidelity when
     // mapping other operations onto fmed3 since the order of operands is
     // unchanged.
diff --git a/llvm/test/Transforms/InstCombine/AMDGPU/amdgcn-intrinsics.ll b/llvm/test/Transforms/InstCombine/AMDGPU/amdgcn-intrinsics.ll
index 14f31280cc878..cfc0e345aaa3d 100644
--- a/llvm/test/Transforms/InstCombine/AMDGPU/amdgcn-intrinsics.ll
+++ b/llvm/test/Transforms/InstCombine/AMDGPU/amdgcn-intrinsics.ll
@@ -2113,6 +2113,30 @@ define float @fmed3_0_1_undef_f32() {
   ret float %med
 }
 
+define float @fmed3_poison_x_y_f32(float %x, float %y) {
+; CHECK-LABEL: @fmed3_poison_x_y_f32(
+; CHECK-NEXT:    ret float poison
+;
+  %med3 = call float @llvm.amdgcn.fmed3.f32(float poison, float %x, float %y)
+  ret float %med3
+}
+
+define float @fmed3_x_poison_y_f32(float %x, float %y) {
+; CHECK-LABEL: @fmed3_x_poison_y_f32(
+; CHECK-NEXT:    ret float poison
+;
+  %med3 = call float @llvm.amdgcn.fmed3.f32(float %x, float poison, float %y)
+  ret float %med3
+}
+
+define float @fmed3_x_y_poison_f32(float %x, float %y) {
+; CHECK-LABEL: @fmed3_x_y_poison_f32(
+; CHECK-NEXT:    ret float poison
+;
+  %med3 = call float @llvm.amdgcn.fmed3.f32(float %x, float %y, float poison)
+  ret float %med3
+}
+
 ; --------------------------------------------------------------------
 ; llvm.amdgcn.icmp
 ; --------------------------------------------------------------------

@arsenm arsenm marked this pull request as ready for review March 13, 2025 03:44
@llvmbot llvmbot added llvm:instcombine Covers the InstCombine, InstSimplify and AggressiveInstCombine passes llvm:transforms labels Mar 13, 2025
Copy link
Contributor

@pravinjagtap pravinjagtap left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@arsenm arsenm force-pushed the users/arsenm/amdgpu/propagate-poison-cvt-pk-intrinsics branch from c2fad37 to bd6f2f2 Compare March 14, 2025 01:21
@arsenm arsenm force-pushed the users/arsenm/amdgpu/propagate-poison-fmed3-intrinsic branch from aac10b7 to 4b8aef2 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:28 AM EDT: Graphite rebased this pull request as part of a merge.
  • Mar 14, 12:30 AM EDT: A user merged this pull request with Graphite.

@arsenm arsenm force-pushed the users/arsenm/amdgpu/propagate-poison-cvt-pk-intrinsics branch from bd6f2f2 to d17bc7f Compare March 14, 2025 04:25
Base automatically changed from users/arsenm/amdgpu/propagate-poison-cvt-pk-intrinsics to main March 14, 2025 04:27
@arsenm arsenm force-pushed the users/arsenm/amdgpu/propagate-poison-fmed3-intrinsic branch from 4b8aef2 to fb1107d Compare March 14, 2025 04:28
@arsenm arsenm merged commit 0d8a22d into main Mar 14, 2025
6 of 10 checks passed
@arsenm arsenm deleted the users/arsenm/amdgpu/propagate-poison-fmed3-intrinsic branch March 14, 2025 04:30
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