Skip to content

Commit 48b23c0

Browse files
authored
AMDGPU: Handle undef correctly in isKnownIntegral (llvm#92566)
1 parent 770d928 commit 48b23c0

File tree

2 files changed

+54
-6
lines changed

2 files changed

+54
-6
lines changed

llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -577,18 +577,26 @@ bool AMDGPULibCalls::fold_read_write_pipe(CallInst *CI, IRBuilder<> &B,
577577

578578
static bool isKnownIntegral(const Value *V, const DataLayout &DL,
579579
FastMathFlags FMF) {
580-
if (isa<UndefValue>(V))
580+
if (isa<PoisonValue>(V))
581581
return true;
582+
if (isa<UndefValue>(V))
583+
return false;
582584

583585
if (const ConstantFP *CF = dyn_cast<ConstantFP>(V))
584586
return CF->getValueAPF().isInteger();
585587

586-
if (const ConstantDataVector *CDV = dyn_cast<ConstantDataVector>(V)) {
587-
for (unsigned i = 0, e = CDV->getNumElements(); i != e; ++i) {
588-
Constant *ConstElt = CDV->getElementAsConstant(i);
589-
if (isa<UndefValue>(ConstElt))
588+
auto *VFVTy = dyn_cast<FixedVectorType>(V->getType());
589+
const Constant *CV = dyn_cast<Constant>(V);
590+
if (VFVTy && CV) {
591+
unsigned NumElts = VFVTy->getNumElements();
592+
for (unsigned i = 0; i != NumElts; ++i) {
593+
Constant *Elt = CV->getAggregateElement(i);
594+
if (!Elt)
595+
return false;
596+
if (isa<PoisonValue>(Elt))
590597
continue;
591-
const ConstantFP *CFP = dyn_cast<ConstantFP>(ConstElt);
598+
599+
const ConstantFP *CFP = dyn_cast<ConstantFP>(Elt);
592600
if (!CFP || !CFP->getValue().isInteger())
593601
return false;
594602
}

llvm/test/CodeGen/AMDGPU/amdgpu-simplify-libcall-pow.ll

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2673,6 +2673,46 @@ define float @test_pow_f32__y_known_integral_roundeven(float %x, float nofpclass
26732673
ret float %pow
26742674
}
26752675

2676+
define float @test_pow_f32_known_integral_undef(float %x) {
2677+
; CHECK-LABEL: define float @test_pow_f32_known_integral_undef
2678+
; CHECK-SAME: (float [[X:%.*]]) {
2679+
; CHECK-NEXT: [[POW:%.*]] = tail call float @_Z3powff(float [[X]], float undef)
2680+
; CHECK-NEXT: ret float [[POW]]
2681+
;
2682+
%pow = tail call float @_Z3powff(float %x, float undef)
2683+
ret float %pow
2684+
}
2685+
2686+
define float @test_pow_f32_known_integral_poison(float %x) {
2687+
; CHECK-LABEL: define float @test_pow_f32_known_integral_poison
2688+
; CHECK-SAME: (float [[X:%.*]]) {
2689+
; CHECK-NEXT: [[POW:%.*]] = tail call float @_Z4pownfi(float [[X]], i32 poison)
2690+
; CHECK-NEXT: ret float [[POW]]
2691+
;
2692+
%pow = tail call float @_Z3powff(float %x, float poison)
2693+
ret float %pow
2694+
}
2695+
2696+
define <2 x float> @test_pow_v2f32_known_integral_constant_vector_undef_elt(<2 x float> %x) {
2697+
; CHECK-LABEL: define <2 x float> @test_pow_v2f32_known_integral_constant_vector_undef_elt
2698+
; CHECK-SAME: (<2 x float> [[X:%.*]]) {
2699+
; CHECK-NEXT: [[POW:%.*]] = tail call <2 x float> @_Z3powDv2_fS_(<2 x float> [[X]], <2 x float> <float 4.000000e+00, float undef>)
2700+
; CHECK-NEXT: ret <2 x float> [[POW]]
2701+
;
2702+
%pow = tail call <2 x float> @_Z3powDv2_fS_(<2 x float> %x, <2 x float> <float 4.0, float undef>)
2703+
ret <2 x float> %pow
2704+
}
2705+
2706+
define <2 x float> @test_pow_v2f32_known_integral_constant_vector_poison_elt(<2 x float> %x) {
2707+
; CHECK-LABEL: define <2 x float> @test_pow_v2f32_known_integral_constant_vector_poison_elt
2708+
; CHECK-SAME: (<2 x float> [[X:%.*]]) {
2709+
; CHECK-NEXT: [[POW:%.*]] = tail call <2 x float> @_Z4pownDv2_fDv2_i(<2 x float> [[X]], <2 x i32> <i32 4, i32 poison>)
2710+
; CHECK-NEXT: ret <2 x float> [[POW]]
2711+
;
2712+
%pow = tail call <2 x float> @_Z3powDv2_fS_(<2 x float> %x, <2 x float> <float 4.0, float poison>)
2713+
ret <2 x float> %pow
2714+
}
2715+
26762716
attributes #0 = { minsize }
26772717
attributes #1 = { noinline }
26782718
attributes #2 = { strictfp }

0 commit comments

Comments
 (0)