[llvm] [LoopIdiom] Reland: Support 'shift until less-than' idiom #95002 (PR #98298)
David Sherwood via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 10 06:25:05 PDT 2024
================
@@ -1545,12 +1545,15 @@ static Value *matchShiftULTCondition(BranchInst *BI, BasicBlock *LoopEntry,
BasicBlock *FalseSucc = BI->getSuccessor(1);
ICmpInst::Predicate Pred = Cond->getPredicate();
- if (Pred == ICmpInst::ICMP_ULT && FalseSucc == LoopEntry) {
- Threshold = CmpConst->getZExtValue();
- return Cond->getOperand(0);
- }
+ if (Pred != ICmpInst::ICMP_ULT || FalseSucc != LoopEntry)
+ return nullptr;
- return nullptr;
+ std::optional<uint64_t> ValIntOpt = CmpConst->getValue().tryZExtValue();
----------------
david-arm wrote:
So I think this works because in practice the caller only does something useful if the threshold is 2 or 4. However, in future we may want to extend support for recognising idioms with greater thresholds. I do wonder if perhaps it's simpler (and more future-proof) to just return the threshold as a APInt instead of uint64_t? That way you hardly need to change this function at all and just do:
```
if (Pred == ICmpInst::ICMP_ULT && FalseSucc == LoopEntry) {
Threshold = CmpConst->getValue();
return Cond->getOperand(0);
}
```
The checks for threshold == 2 or threshold == 4 later on should just work when it's a APInt I think. What do you think?
https://github.com/llvm/llvm-project/pull/98298
More information about the llvm-commits
mailing list