[PATCH] Add an instcombine rule to optimize max(~a, ~b) to ~min(a, b) when profitable
Sanjoy Das
sanjoy at playingwithpointers.com
Sun Feb 22 23:17:31 PST 2015
================
Comment at: lib/Transforms/InstCombine/InstCombineSelect.cpp:1182
@@ +1181,3 @@
+ if (BO->getOpcode() == Instruction::Add ||
+ BO->getOpcode() == Instruction::Sub)
+ return isa<Constant>(BO->getOperand(0)) ||
----------------
filcab wrote:
> We do this test here, but the calculation for Profitable only cares about Not.
> Do we really need this (or should we just check for this in the Porfitable calculation too)?
The `Profitable` check is intentionally more restrictive. You don't gain or lose anything if you compute `(-1-Const) - A` instead of `Const + A`, so there is no penalty. But the profitable check is specifically about figuring out if computing `~V` instead of `V` *gains* you anything -- if `V` was `xor P, -1` then you can now get away without actually computing the `xor`. The profitability check has to be stronger than a break-even since this rule introduces a `not` and that extra work has to be justified.
http://reviews.llvm.org/D7821
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
More information about the llvm-commits
mailing list