Skip to content

AMDGPU: Handle undef correctly in isKnownIntegral #92566

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,18 +577,26 @@ bool AMDGPULibCalls::fold_read_write_pipe(CallInst *CI, IRBuilder<> &B,

static bool isKnownIntegral(const Value *V, const DataLayout &DL,
FastMathFlags FMF) {
if (isa<UndefValue>(V))
if (isa<PoisonValue>(V))
return true;
if (isa<UndefValue>(V))
return false;

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

if (const ConstantDataVector *CDV = dyn_cast<ConstantDataVector>(V)) {
for (unsigned i = 0, e = CDV->getNumElements(); i != e; ++i) {
Constant *ConstElt = CDV->getElementAsConstant(i);
if (isa<UndefValue>(ConstElt))
auto *VFVTy = dyn_cast<FixedVectorType>(V->getType());
const Constant *CV = dyn_cast<Constant>(V);
if (VFVTy && CV) {
unsigned NumElts = VFVTy->getNumElements();
for (unsigned i = 0; i != NumElts; ++i) {
Constant *Elt = CV->getAggregateElement(i);
if (!Elt)
return false;
if (isa<PoisonValue>(Elt))
continue;
const ConstantFP *CFP = dyn_cast<ConstantFP>(ConstElt);

const ConstantFP *CFP = dyn_cast<ConstantFP>(Elt);
if (!CFP || !CFP->getValue().isInteger())
return false;
}
Expand Down
40 changes: 40 additions & 0 deletions llvm/test/CodeGen/AMDGPU/amdgpu-simplify-libcall-pow.ll
Original file line number Diff line number Diff line change
Expand Up @@ -2673,6 +2673,46 @@ define float @test_pow_f32__y_known_integral_roundeven(float %x, float nofpclass
ret float %pow
}

define float @test_pow_f32_known_integral_undef(float %x) {
; CHECK-LABEL: define float @test_pow_f32_known_integral_undef
; CHECK-SAME: (float [[X:%.*]]) {
; CHECK-NEXT: [[POW:%.*]] = tail call float @_Z3powff(float [[X]], float undef)
; CHECK-NEXT: ret float [[POW]]
;
%pow = tail call float @_Z3powff(float %x, float undef)
ret float %pow
}

define float @test_pow_f32_known_integral_poison(float %x) {
; CHECK-LABEL: define float @test_pow_f32_known_integral_poison
; CHECK-SAME: (float [[X:%.*]]) {
; CHECK-NEXT: [[POW:%.*]] = tail call float @_Z4pownfi(float [[X]], i32 poison)
; CHECK-NEXT: ret float [[POW]]
;
%pow = tail call float @_Z3powff(float %x, float poison)
ret float %pow
}

define <2 x float> @test_pow_v2f32_known_integral_constant_vector_undef_elt(<2 x float> %x) {
; CHECK-LABEL: define <2 x float> @test_pow_v2f32_known_integral_constant_vector_undef_elt
; CHECK-SAME: (<2 x float> [[X:%.*]]) {
; CHECK-NEXT: [[POW:%.*]] = tail call <2 x float> @_Z3powDv2_fS_(<2 x float> [[X]], <2 x float> <float 4.000000e+00, float undef>)
; CHECK-NEXT: ret <2 x float> [[POW]]
;
%pow = tail call <2 x float> @_Z3powDv2_fS_(<2 x float> %x, <2 x float> <float 4.0, float undef>)
ret <2 x float> %pow
}

define <2 x float> @test_pow_v2f32_known_integral_constant_vector_poison_elt(<2 x float> %x) {
; CHECK-LABEL: define <2 x float> @test_pow_v2f32_known_integral_constant_vector_poison_elt
; CHECK-SAME: (<2 x float> [[X:%.*]]) {
; CHECK-NEXT: [[POW:%.*]] = tail call <2 x float> @_Z4pownDv2_fDv2_i(<2 x float> [[X]], <2 x i32> <i32 4, i32 poison>)
; CHECK-NEXT: ret <2 x float> [[POW]]
;
%pow = tail call <2 x float> @_Z3powDv2_fS_(<2 x float> %x, <2 x float> <float 4.0, float poison>)
ret <2 x float> %pow
}

attributes #0 = { minsize }
attributes #1 = { noinline }
attributes #2 = { strictfp }
Expand Down
Loading