This is an archive of the discontinued LLVM Phabricator instance.

[ScalarEvolution] Enhance Predicate implication from condition
Needs RevisionPublic

Authored by TiehuZhang on Feb 24 2023, 3:53 AM.

Details

Summary

We can prove the scenario:

FoundLHS > FoundRHS =>
LHS = (FoundLHS + Offset) > RHS = (FoundRHS + Offset)

Or

FoundLHS < FoundRHS =>
LHS = (FoundLHS + Offset) < RHS = (FoundRHS + Offset)

This patch enhance isImpliedCondBalancedTypes with the formula.

Diff Detail

Event Timeline

TiehuZhang created this revision.Feb 24 2023, 3:53 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 24 2023, 3:53 AM
TiehuZhang requested review of this revision.Feb 24 2023, 3:53 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 24 2023, 3:53 AM
TiehuZhang retitled this revision from [ScalarEvolution] Precommit a test to [ScalarEvolution] Enhance Predicate implication from condition.Feb 24 2023, 3:55 AM
TiehuZhang edited the summary of this revision. (Show Details)
mkazantsev requested changes to this revision.Feb 27 2023, 8:35 PM
mkazantsev added inline comments.
llvm/lib/Analysis/ScalarEvolution.cpp
11768

This is incorrect in case of overflow. See isKnownPredicateViaNoOverflow.

This revision now requires changes to proceed.Feb 27 2023, 8:35 PM
mkazantsev added inline comments.Feb 27 2023, 8:44 PM
llvm/test/Transforms/HardwareLoops/ARM/simple-do.ll
151

This is miscompile, see https://alive2.llvm.org/ce/z/ESPqU_

TiehuZhang added inline comments.Feb 27 2023, 9:09 PM
llvm/lib/Analysis/ScalarEvolution.cpp
11768

This is incorrect in case of overflow. See isKnownPredicateViaNoOverflow.

llvm/test/Transforms/HardwareLoops/ARM/simple-do.ll
151

Thanks for your review! https://alive2.llvm.org/ is really a useful tool. Sometimes, it is helpful for the performance to simplify -1,+,(-1 * %max_row_length)}<nw><%for.cond1.preheader> + ({1,+,%max_row_length}<nw><%for.cond1.preheader> smax {%max_row_length,+,%max_row_length}<nw><%for.cond1.preheader> to -1 + %max_row_length . For most cases, smax is redundant, and may hurt performance. But if overflow is considered, this check is indispensable. I'll try to restrict the condition of the patch to ensure the correctness. For the scenario, do you have any suggestions?