[clang] [llvm] [AMDGPU] Improve selection of ballot.i64 intrinsic in wave32 mode. (PR #71556)

Valery Pykhtin via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 29 02:59:06 PST 2023


================
@@ -961,6 +961,18 @@ GCNTTIImpl::instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const {
         return IC.replaceInstUsesWith(II, Constant::getNullValue(II.getType()));
       }
     }
+    if (ST->isWave32() && II.getType()->getIntegerBitWidth() == 64) {
+      // %b64 = call i64 ballot.i64(...)
+      // =>
+      // %b32 = call i32 ballot.i32(...)
+      // %b64 = zext i32 %b32 to i64
+      Function *NewF = Intrinsic::getDeclaration(
+          II.getModule(), Intrinsic::amdgcn_ballot, {IC.Builder.getInt32Ty()});
+      CallInst *NewCall = IC.Builder.CreateCall(NewF, {II.getArgOperand(0)});
+      Value *CastedCall = IC.Builder.CreateZExtOrBitCast(NewCall, II.getType());
+      CastedCall->takeName(&II);
+      return IC.replaceInstUsesWith(II, CastedCall);
----------------
vpykhtin wrote:

Thanks, changed to `IC.Builder.CreateIntrinsic`. I decided to use it as a temp for `CreateZExtOrBitCast`.

https://github.com/llvm/llvm-project/pull/71556


More information about the cfe-commits mailing list