https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/131060
>From 4b8aef2f108aeb71dc1ffb29392cbb1a4548a576 Mon Sep 17 00:00:00 2001 From: Matt Arsenault <matthew.arsena...@amd.com> Date: Thu, 13 Mar 2025 10:37:11 +0700 Subject: [PATCH] AMDGPU: Make fmed3 intrinsic propagate poison --- .../AMDGPU/AMDGPUInstCombineIntrinsic.cpp | 5 ++++ .../InstCombine/AMDGPU/amdgcn-intrinsics.ll | 24 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp b/llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp index e1ab33c399b0b..02977a61efb55 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp @@ -827,6 +827,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 2f64e4d15f357..af5c66165e67e 100644 --- a/llvm/test/Transforms/InstCombine/AMDGPU/amdgcn-intrinsics.ll +++ b/llvm/test/Transforms/InstCombine/AMDGPU/amdgcn-intrinsics.ll @@ -2121,6 +2121,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 ; -------------------------------------------------------------------- _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits