@@ -8989,27 +8989,24 @@ enum SpecialRegisterAccessKind {
89898989 Write,
89908990};
89918991
8992+ // Generates the IR for __builtin_read_exec_*.
8993+ // Lowers the builtin to amdgcn_ballot intrinsic.
89928994static Value *EmitAMDGCNBallotForExec(CodeGenFunction &CGF, const CallExpr *E,
89938995 llvm::Type *RegisterType,
89948996 llvm::Type *ValueType, bool isExecHi) {
89958997 CodeGen::CGBuilderTy &Builder = CGF.Builder;
89968998 CodeGen::CodeGenModule &CGM = CGF.CGM;
89978999
8998- llvm::Type *ResultType = CGF.ConvertType(E->getType() );
8999- llvm::Value *Call;
9000- Function *F;
9000+ Function *F = CGM.getIntrinsic(Intrinsic::amdgcn_ballot, {RegisterType} );
9001+ llvm::Value *Call = Builder.CreateCall(F, {Builder.getInt1(true)}) ;
9002+
90019003 if (isExecHi) {
9002- F = CGM.getIntrinsic(Intrinsic::amdgcn_ballot, {RegisterType});
9003- Call = Builder.CreateCall(F, {Builder.getInt1(true)});
9004- Value *C1 = llvm::ConstantInt::get(ValueType, 32);
9005- Value *Rt2 = Builder.CreateLShr(Call, C1);
9006- Value *Rt3 = Builder.CreateTruncOrBitCast(Rt2, CGF.Int32Ty);
9007- return Rt3;
9008- } else {
9009- F = CGM.getIntrinsic(Intrinsic::amdgcn_ballot, {ResultType});
9010- Call = Builder.CreateCall(F, {Builder.getInt1(true)});
9011- return Call;
9004+ Value *Rt2 = Builder.CreateLShr(Call, 32);
9005+ Rt2 = Builder.CreateTrunc(Rt2, CGF.Int32Ty);
9006+ return Rt2;
90129007 }
9008+
9009+ return Call;
90139010}
90149011
90159012// Generates the IR for the read/write special register builtin,
0 commit comments