[llvm] [InstCombine] Add assume-based optimizations for equality and AMDGPU ballot patterns (PR #160670)
Sameer Sahasrabuddhe via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 5 09:47:46 PDT 2025
================
@@ -3540,6 +3540,79 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
}
}
+ // Basic assume equality optimization: assume(x == c) -> replace dominated uses of x with c
+ if (auto *ICmp = dyn_cast<ICmpInst>(IIOperand)) {
+ if (ICmp->getPredicate() == ICmpInst::ICMP_EQ) {
+ Value *LHS = ICmp->getOperand(0);
+ Value *RHS = ICmp->getOperand(1);
+ Value *Variable = nullptr;
+ Constant *ConstantVal = nullptr;
+
+ if (auto *C = dyn_cast<Constant>(RHS)) {
+ Variable = LHS;
+ ConstantVal = C;
+ } else if (auto *C = dyn_cast<Constant>(LHS)) {
+ Variable = RHS;
+ ConstantVal = C;
+ }
+
+ if (Variable && ConstantVal && Variable->hasUseList()) {
+ SmallVector<Use *, 8> DominatedUses;
+ for (Use &U : Variable->uses()) {
+ if (auto *UseInst = dyn_cast<Instruction>(U.getUser())) {
----------------
ssahasra wrote:
Rephrasing, _I believe_ that the `dyn_cast` will always succeed, and hence it can be replaced with a `cast`. But I do need confirmation that my belief is right. Also, what dominance check?
https://github.com/llvm/llvm-project/pull/160670
More information about the llvm-commits
mailing list