Skip to content

Commit 4a3ee4f

Browse files
authored
AMDGPU: Make fma_legacy intrinsic propagate poison (#131063)
1 parent 3770689 commit 4a3ee4f

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
@@ -1282,6 +1282,11 @@ GCNTTIImpl::instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const {
12821282
Value *Op1 = II.getArgOperand(1);
12831283
Value *Op2 = II.getArgOperand(2);
12841284

1285+
for (Value *Src : {Op0, Op1, Op2}) {
1286+
if (isa<PoisonValue>(Src))
1287+
return IC.replaceInstUsesWith(II, Src);
1288+
}
1289+
12851290
// The legacy behaviour is that multiplying +/-0.0 by anything, even NaN or
12861291
// infinity, gives +0.0.
12871292
// TODO: Move to InstSimplify?

llvm/test/Transforms/InstCombine/AMDGPU/fma_legacy.ll

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,30 @@ define float @test_finite_assumed(float %x, float %y, float %z) {
105105
ret float %call
106106
}
107107

108+
define float @test_poison_x_y(float %x, float %y) {
109+
; CHECK-LABEL: @test_poison_x_y(
110+
; CHECK-NEXT: ret float poison
111+
;
112+
%call = call float @llvm.amdgcn.fma.legacy(float poison, float %x, float %y)
113+
ret float %call
114+
}
115+
116+
define float @test_x_poison_y(float %x, float %y) {
117+
; CHECK-LABEL: @test_x_poison_y(
118+
; CHECK-NEXT: ret float poison
119+
;
120+
%call = call float @llvm.amdgcn.fma.legacy(float %x, float poison, float %y)
121+
ret float %call
122+
}
123+
124+
define float @test_x_y_poison_y(float %x, float %y) {
125+
; CHECK-LABEL: @test_x_y_poison_y(
126+
; CHECK-NEXT: ret float poison
127+
;
128+
%call = call float @llvm.amdgcn.fma.legacy(float %x, float %y, float poison)
129+
ret float %call
130+
}
131+
108132
declare float @llvm.amdgcn.fma.legacy(float, float, float)
109133
declare float @llvm.fabs.f32(float)
110134
declare void @llvm.assume(i1 noundef)

0 commit comments

Comments
 (0)