[llvm] [WIP][InstCombine] Add assume-based optimizations for equality and AMDGPU ballot patterns (PR #160670)
Pankaj Dwivedi via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 15 02:26:14 PDT 2025
================
@@ -2206,6 +2207,23 @@ bool GVNPass::processAssumeIntrinsic(AssumeInst *IntrinsicI) {
std::swap(CmpLHS, CmpRHS);
}
+ // Optimize AMDGPU ballot pattern: assume(ballot(cmp) == -1) or
+ // assume(ballot(cmp) == exec_mask). This implies cmp is true on all
+ // active lanes and hence can be replaced with true.
+ if (isa<IntrinsicInst>(CmpLHS) && isa<Constant>(CmpRHS)) {
+ auto *IntrCall = cast<IntrinsicInst>(CmpLHS);
+ // Check if CmpLHS is a ballot intrinsic
+ if (IntrCall->getIntrinsicID() ==
+ Intrinsic::AMDGCNIntrinsics::amdgcn_ballot) {
+ Value *BallotArg = IntrCall->getArgOperand(0);
+ if (BallotArg->getType()->isIntegerTy(1) &&
+ (match(CmpRHS, m_AllOnes()) || !isa<Constant>(CmpRHS))) {
----------------
PankajDwivedi-25 wrote:
> What if it is simply a value that the programmer knows will match the current state of `cmp` across active threads?
In that case, it will be too complex to determine the state of cmp; at least, I can't see why `assume(ballot(cmp) == arbitrary)` is true.
Possibly we can we ignore it?
https://github.com/llvm/llvm-project/pull/160670
More information about the llvm-commits
mailing list