Skip to content

Commit d0676db

Browse files
Refactored the ballot optimization condition into propagateEquality method
1 parent af85d9e commit d0676db

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

llvm/lib/Transforms/Scalar/GVN.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2540,6 +2540,21 @@ bool GVNPass::propagateEquality(
25402540
}
25412541
}
25422542

2543+
// If "ballot(cond) == -1" or "ballot(cond) == exec_mask" then cond is true
2544+
// on all active lanes, so cond can be replaced with true.
2545+
if (IntrinsicInst *IntrCall = dyn_cast<IntrinsicInst>(LHS)) {
2546+
if (IntrCall->getIntrinsicID() ==
2547+
Intrinsic::AMDGCNIntrinsics::amdgcn_ballot) {
2548+
Value *BallotArg = IntrCall->getArgOperand(0);
2549+
if (BallotArg->getType()->isIntegerTy(1) &&
2550+
(match(RHS, m_AllOnes()) || !isa<Constant>(RHS))) {
2551+
Worklist.push_back(std::make_pair(
2552+
BallotArg, ConstantInt::getTrue(BallotArg->getType())));
2553+
continue;
2554+
}
2555+
}
2556+
}
2557+
25432558
// Now try to deduce additional equalities from this one. For example, if
25442559
// the known equality was "(A != B)" == "false" then it follows that A and B
25452560
// are equal in the scope. Only boolean equalities with an explicit true or

0 commit comments

Comments
 (0)