Skip to content

Commit 4b8aef2

Browse files
committed
AMDGPU: Make fmed3 intrinsic propagate poison
1 parent bd6f2f2 commit 4b8aef2

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,11 @@ GCNTTIImpl::instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const {
827827
Value *Src1 = II.getArgOperand(1);
828828
Value *Src2 = II.getArgOperand(2);
829829

830+
for (Value *Src : {Src0, Src1, Src2}) {
831+
if (isa<PoisonValue>(Src))
832+
return IC.replaceInstUsesWith(II, Src);
833+
}
834+
830835
// Checking for NaN before canonicalization provides better fidelity when
831836
// mapping other operations onto fmed3 since the order of operands is
832837
// unchanged.

llvm/test/Transforms/InstCombine/AMDGPU/amdgcn-intrinsics.ll

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2121,6 +2121,30 @@ define float @fmed3_0_1_undef_f32() {
21212121
ret float %med
21222122
}
21232123

2124+
define float @fmed3_poison_x_y_f32(float %x, float %y) {
2125+
; CHECK-LABEL: @fmed3_poison_x_y_f32(
2126+
; CHECK-NEXT: ret float poison
2127+
;
2128+
%med3 = call float @llvm.amdgcn.fmed3.f32(float poison, float %x, float %y)
2129+
ret float %med3
2130+
}
2131+
2132+
define float @fmed3_x_poison_y_f32(float %x, float %y) {
2133+
; CHECK-LABEL: @fmed3_x_poison_y_f32(
2134+
; CHECK-NEXT: ret float poison
2135+
;
2136+
%med3 = call float @llvm.amdgcn.fmed3.f32(float %x, float poison, float %y)
2137+
ret float %med3
2138+
}
2139+
2140+
define float @fmed3_x_y_poison_f32(float %x, float %y) {
2141+
; CHECK-LABEL: @fmed3_x_y_poison_f32(
2142+
; CHECK-NEXT: ret float poison
2143+
;
2144+
%med3 = call float @llvm.amdgcn.fmed3.f32(float %x, float %y, float poison)
2145+
ret float %med3
2146+
}
2147+
21242148
; --------------------------------------------------------------------
21252149
; llvm.amdgcn.icmp
21262150
; --------------------------------------------------------------------

0 commit comments

Comments
 (0)