If a condition is calculated only once, and there are multiple guards on this condition, we should be able
to remove all guards dominated by the first of them. This patch allows EarlyCSE to try to find the condition
of a guard among the known values, and if it is true, remove the guard. Otherwise we keep the guard and
mark its condition as 'true' for future consideration.
Details
Diff Detail
Event Timeline
lib/Transforms/Scalar/EarlyCSE.cpp | ||
---|---|---|
661 | I think this would be a bit clearer if put under the canHandle branch. i.e. if (auto *KnownCond = ...) { ... } AV.insert(CondI, True); } | |
664 | Use isa<ConstantInt>(KnownCond) && cast<ConstantInt>(KnownCond)->isOneValue(); This also might be a case where dyn_cast_or_null would be useful. Finally, if we've inferred the value to constant false, we should replace the operand with the constant. Don't bother going beyond that for the moment (i.e. exploiting the unreached code), but there's no reason not to put in the constant. | |
test/Transforms/EarlyCSE/guards.ll | ||
6 | minor: submit a separate patch without further review for the test name changes to simplify the diff. |
test/Transforms/EarlyCSE/guards.ll | ||
---|---|---|
270 | Not in EarlyCSE (which isn't allowed to modify CFG). We can fold the condition to false at use though. That should be a separate patch. |
Addressed the comments.
test/Transforms/EarlyCSE/guards.ll | ||
---|---|---|
6 | Actually I've looked into other tests for EarlyCSE and decided to keep the naming as is for consistency. |
lib/Transforms/Scalar/EarlyCSE.cpp | ||
---|---|---|
679 | You should be able to do if (match(KnownCond, m_One())) to make it a bit more concise, but what you have now is fine too. |
I think this would be a bit clearer if put under the canHandle branch. i.e.
if (canHandle(CondI)) {
}