@@ -96,12 +96,12 @@ AMDGPUUniformIntrinsicCombinePass::run(Function &F,
9696bool AMDGPUUniformIntrinsicCombineImpl::run (Function &F) {
9797 bool IsChanged{false };
9898 Module *M = F.getParent ();
99-
99+
100100 // If none of the relevant intrinsics are declared, return early.
101- // if (!M->getFunction( Intrinsic::getName( Intrinsic::amdgcn_permlane64) ) &&
102- // !M->getFunction( Intrinsic::getName( Intrinsic::amdgcn_readfirstlane) ) &&
103- // !M->getFunction( Intrinsic::getName( Intrinsic::amdgcn_readlane) ) &&
104- // !M->getFunction( Intrinsic::getName( Intrinsic::amdgcn_ballot) )) {
101+ // if (!Intrinsic::getDeclarationIfExists(M, Intrinsic::amdgcn_permlane64, {} ) &&
102+ // !Intrinsic::getDeclarationIfExists(M, Intrinsic::amdgcn_readfirstlane, {} ) &&
103+ // !Intrinsic::getDeclarationIfExists(M, Intrinsic::amdgcn_readlane, {} ) &&
104+ // !Intrinsic::getDeclarationIfExists(M, Intrinsic::amdgcn_ballot, {} )) {
105105 // return false;
106106 // }
107107
@@ -139,28 +139,21 @@ bool AMDGPUUniformIntrinsicCombineImpl::optimizeUniformIntrinsicInst(
139139 LLVM_DEBUG (dbgs () << " Found uniform ballot intrinsic: " << II << " \n " );
140140
141141 // Look for a direct `icmp eq` use of the ballot result.
142- // FIXME: replace all the uses?
143- auto It = llvm::find_if (II.users (), [&](User *U) {
144- return match (U, m_ICmp (m_Specific (&II), m_Zero ()));
145- });
146-
147- // Check if a match was found
148- if (It == II.user_end ())
149- return false ;
150-
151- // Extract the matching `icmp` instruction
152- ICmpInst *ICmp = dyn_cast<ICmpInst>(*It);
153- IRBuilder<> Builder (ICmp);
154-
155- // Convert ballot argument to match `icmp` operand type (i64)
156- Value *ConvertedSrc = Builder.CreateZExtOrTrunc (Src, II.getType ());
157-
158- LLVM_DEBUG (dbgs () << " Replacing ballot result in icmp: " << *ICmp
159- << " with " << *ConvertedSrc << " \n " );
160-
161- // Replace `%ballot` in `icmp` with `ConvertedSrc`
162- ICmp->setOperand (0 , ConvertedSrc);
163- return true ;
142+ bool Changed = false ;
143+ for (User *U : make_early_inc_range (II.users ())) {
144+ if (match (U, m_ICmp (m_Specific (&II), m_Zero ()))) {
145+ ICmpInst *ICmp = dyn_cast<ICmpInst>(U);
146+ IRBuilder<> Builder (ICmp);
147+ Value *ConvertedSrc = Builder.CreateZExtOrTrunc (Src, II.getType ());
148+
149+ LLVM_DEBUG (dbgs () << " Replacing ballot result in icmp: " << *ICmp
150+ << " with " << *ConvertedSrc << " \n " );
151+
152+ ICmp->setOperand (0 , ConvertedSrc);
153+ Changed = true ;
154+ }
155+ }
156+ return Changed;
164157 }
165158 }
166159 return false ;
0 commit comments