Skip to content

Commit d8f17b3

Browse files
authored
AMDGPU: Make sqrt and rsq intrinsics propagate poison (#130914)
1 parent 95ab95f commit d8f17b3

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,8 @@ GCNTTIImpl::instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const {
548548
case Intrinsic::amdgcn_sqrt:
549549
case Intrinsic::amdgcn_rsq: {
550550
Value *Src = II.getArgOperand(0);
551+
if (isa<PoisonValue>(Src))
552+
return IC.replaceInstUsesWith(II, Src);
551553

552554
// TODO: Move to ConstantFolding/InstSimplify?
553555
if (isa<UndefValue>(Src)) {

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ declare half @llvm.amdgcn.sqrt.f16(half) nounwind readnone
8989
declare float @llvm.amdgcn.sqrt.f32(float) nounwind readnone
9090
declare double @llvm.amdgcn.sqrt.f64(double) nounwind readnone
9191

92+
define half @test_constant_fold_sqrt_f16_poison() nounwind {
93+
; CHECK-LABEL: @test_constant_fold_sqrt_f16_poison(
94+
; CHECK-NEXT: ret half poison
95+
;
96+
%val = call half @llvm.amdgcn.sqrt.f16(half poison) nounwind readnone
97+
ret half %val
98+
}
99+
92100
define half @test_constant_fold_sqrt_f16_undef() nounwind {
93101
; CHECK-LABEL: @test_constant_fold_sqrt_f16_undef(
94102
; CHECK-NEXT: ret half 0xH7E00
@@ -97,6 +105,14 @@ define half @test_constant_fold_sqrt_f16_undef() nounwind {
97105
ret half %val
98106
}
99107

108+
define float @test_constant_fold_sqrt_f32_poison() nounwind {
109+
; CHECK-LABEL: @test_constant_fold_sqrt_f32_poison(
110+
; CHECK-NEXT: ret float poison
111+
;
112+
%val = call float @llvm.amdgcn.sqrt.f32(float poison) nounwind readnone
113+
ret float %val
114+
}
115+
100116
define float @test_constant_fold_sqrt_f32_undef() nounwind {
101117
; CHECK-LABEL: @test_constant_fold_sqrt_f32_undef(
102118
; CHECK-NEXT: ret float 0x7FF8000000000000
@@ -234,6 +250,14 @@ define double @test_amdgcn_sqrt_f64(double %arg) {
234250

235251
declare float @llvm.amdgcn.rsq.f32(float) nounwind readnone
236252

253+
define float @test_constant_fold_rsq_f32_poison() nounwind {
254+
; CHECK-LABEL: @test_constant_fold_rsq_f32_poison(
255+
; CHECK-NEXT: ret float poison
256+
;
257+
%val = call float @llvm.amdgcn.rsq.f32(float poison) nounwind readnone
258+
ret float %val
259+
}
260+
237261
define float @test_constant_fold_rsq_f32_undef() nounwind {
238262
; CHECK-LABEL: @test_constant_fold_rsq_f32_undef(
239263
; CHECK-NEXT: ret float 0x7FF8000000000000

0 commit comments

Comments
 (0)