Skip to content

Commit 2dc1a27

Browse files
committed
AMDGPU: Some AMDGPULibCalls cleanups
dyn_cast instead of isa+cast, and initialize on declaration.
1 parent a033bf2 commit 2dc1a27

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -544,12 +544,15 @@ bool AMDGPULibCalls::fold_read_write_pipe(CallInst *CI, IRBuilder<> &B,
544544
auto NumArg = CI->arg_size();
545545
if (NumArg != 4 && NumArg != 6)
546546
return false;
547-
auto *PacketSize = CI->getArgOperand(NumArg - 2);
548-
auto *PacketAlign = CI->getArgOperand(NumArg - 1);
549-
if (!isa<ConstantInt>(PacketSize) || !isa<ConstantInt>(PacketAlign))
547+
ConstantInt *PacketSize =
548+
dyn_cast<ConstantInt>(CI->getArgOperand(NumArg - 2));
549+
ConstantInt *PacketAlign =
550+
dyn_cast<ConstantInt>(CI->getArgOperand(NumArg - 1));
551+
if (!PacketSize || !PacketAlign)
550552
return false;
551-
unsigned Size = cast<ConstantInt>(PacketSize)->getZExtValue();
552-
Align Alignment = cast<ConstantInt>(PacketAlign)->getAlignValue();
553+
554+
unsigned Size = PacketSize->getZExtValue();
555+
Align Alignment = PacketAlign->getAlignValue();
553556
if (Alignment != Size)
554557
return false;
555558

@@ -799,15 +802,14 @@ bool AMDGPULibCalls::fold_pow(CallInst *CI, IRBuilder<> &B,
799802
FInfo.getId() == AMDGPULibFunc::EI_POWN) &&
800803
"fold_pow: encounter a wrong function call");
801804

802-
Value *opr0, *opr1;
805+
Module *M = B.GetInsertBlock()->getModule();
803806
ConstantFP *CF;
804807
ConstantInt *CINT;
805-
ConstantAggregateZero *CZero;
806808
Type *eltType;
809+
Value *opr0 = CI->getArgOperand(0);
810+
Value *opr1 = CI->getArgOperand(1);
811+
ConstantAggregateZero *CZero = dyn_cast<ConstantAggregateZero>(opr1);
807812

808-
opr0 = CI->getArgOperand(0);
809-
opr1 = CI->getArgOperand(1);
810-
CZero = dyn_cast<ConstantAggregateZero>(opr1);
811813
if (getVecSize(FInfo) == 1) {
812814
eltType = opr0->getType();
813815
CF = dyn_cast<ConstantFP>(opr1);
@@ -866,16 +868,15 @@ bool AMDGPULibCalls::fold_pow(CallInst *CI, IRBuilder<> &B,
866868
return true;
867869
}
868870

869-
Module *M = CI->getModule();
870871
if (CF && (CF->isExactlyValue(0.5) || CF->isExactlyValue(-0.5))) {
871872
// pow[r](x, [-]0.5) = sqrt(x)
872873
bool issqrt = CF->isExactlyValue(0.5);
873874
if (FunctionCallee FPExpr =
874875
getFunction(M, AMDGPULibFunc(issqrt ? AMDGPULibFunc::EI_SQRT
875876
: AMDGPULibFunc::EI_RSQRT,
876877
FInfo))) {
877-
LLVM_DEBUG(errs() << "AMDIC: " << *CI << " ---> "
878-
<< FInfo.getName().c_str() << "(" << *opr0 << ")\n");
878+
LLVM_DEBUG(errs() << "AMDIC: " << *CI << " ---> " << FInfo.getName()
879+
<< '(' << *opr0 << ")\n");
879880
Value *nval = CreateCallEx(B,FPExpr, opr0, issqrt ? "__pow2sqrt"
880881
: "__pow2rsqrt");
881882
replaceCall(nval);

0 commit comments

Comments
 (0)