@@ -544,12 +544,15 @@ bool AMDGPULibCalls::fold_read_write_pipe(CallInst *CI, IRBuilder<> &B,
544
544
auto NumArg = CI->arg_size ();
545
545
if (NumArg != 4 && NumArg != 6 )
546
546
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)
550
552
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 ();
553
556
if (Alignment != Size)
554
557
return false ;
555
558
@@ -799,15 +802,14 @@ bool AMDGPULibCalls::fold_pow(CallInst *CI, IRBuilder<> &B,
799
802
FInfo.getId () == AMDGPULibFunc::EI_POWN) &&
800
803
" fold_pow: encounter a wrong function call" );
801
804
802
- Value *opr0, *opr1 ;
805
+ Module *M = B. GetInsertBlock ()-> getModule () ;
803
806
ConstantFP *CF;
804
807
ConstantInt *CINT;
805
- ConstantAggregateZero *CZero;
806
808
Type *eltType;
809
+ Value *opr0 = CI->getArgOperand (0 );
810
+ Value *opr1 = CI->getArgOperand (1 );
811
+ ConstantAggregateZero *CZero = dyn_cast<ConstantAggregateZero>(opr1);
807
812
808
- opr0 = CI->getArgOperand (0 );
809
- opr1 = CI->getArgOperand (1 );
810
- CZero = dyn_cast<ConstantAggregateZero>(opr1);
811
813
if (getVecSize (FInfo) == 1 ) {
812
814
eltType = opr0->getType ();
813
815
CF = dyn_cast<ConstantFP>(opr1);
@@ -866,16 +868,15 @@ bool AMDGPULibCalls::fold_pow(CallInst *CI, IRBuilder<> &B,
866
868
return true ;
867
869
}
868
870
869
- Module *M = CI->getModule ();
870
871
if (CF && (CF->isExactlyValue (0.5 ) || CF->isExactlyValue (-0.5 ))) {
871
872
// pow[r](x, [-]0.5) = sqrt(x)
872
873
bool issqrt = CF->isExactlyValue (0.5 );
873
874
if (FunctionCallee FPExpr =
874
875
getFunction (M, AMDGPULibFunc (issqrt ? AMDGPULibFunc::EI_SQRT
875
876
: AMDGPULibFunc::EI_RSQRT,
876
877
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 " );
879
880
Value *nval = CreateCallEx (B,FPExpr, opr0, issqrt ? " __pow2sqrt"
880
881
: " __pow2rsqrt" );
881
882
replaceCall (nval);
0 commit comments