[llvm] [FuncSpec] Improve handling of Comparison Instructions (PR #114073)
David Sherwood via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 30 08:16:58 PDT 2024
================
@@ -468,16 +468,25 @@ Constant *InstCostVisitor::visitCastInst(CastInst &I) {
Constant *InstCostVisitor::visitCmpInst(CmpInst &I) {
assert(LastVisited != KnownConstants.end() && "Invalid iterator!");
+ Constant *Const = LastVisited->second;
bool Swap = I.getOperand(1) == LastVisited->first;
Value *V = Swap ? I.getOperand(0) : I.getOperand(1);
Constant *Other = findConstantFor(V, KnownConstants);
- if (!Other)
- return nullptr;
- Constant *Const = LastVisited->second;
- return Swap ?
- ConstantFoldCompareInstOperands(I.getPredicate(), Other, Const, DL)
- : ConstantFoldCompareInstOperands(I.getPredicate(), Const, Other, DL);
+ if (Other)
+ return Swap ? ConstantFoldCompareInstOperands(I.getPredicate(), Other,
----------------
david-arm wrote:
I realise you maybe didn't write the original code, but perhaps this is more readable:
```
if (Other) {
if (Swap)
std::swap(Const, Other)
return ConstantFoldCompareInstOperands(I.getPredicate(), Const, Other, DL);
}
```
What do you think?
https://github.com/llvm/llvm-project/pull/114073
More information about the llvm-commits
mailing list