This is an archive of the discontinued LLVM Phabricator instance.

[EarlyCSE] Use m_LogicalAnd/Or matchers to handle branch conditions
ClosedPublic

Authored by aqjune on Dec 27 2020, 11:28 AM.

Details

Summary

EarlyCSE's handleBranchCondition says:

// If the condition is AND operation, we can propagate its operands into the
// true branch. If it is OR operation, we can propagate them into the false
// branch.

This holds for the corresponding select patterns as well.

This is a part of an ongoing work for disabling buggy select->and/or transformations.
See llvm.org/pr48353 and D93065 for more context

Proof:
and: https://alive2.llvm.org/ce/z/MQWodU
or: https://alive2.llvm.org/ce/z/9GLbB_

Diff Detail

Event Timeline

aqjune created this revision.Dec 27 2020, 11:28 AM
aqjune requested review of this revision.Dec 27 2020, 11:28 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 27 2020, 11:28 AM
nikic added inline comments.Dec 27 2020, 12:12 PM
llvm/lib/Transforms/Scalar/EarlyCSE.cpp
1078

As clang-format points out, these braces were probably intended to go around the whole block? With that fixed, you should be able to drop the nullptr initialization and use dyn_cast instead of dyn_cast_or_null below.

aqjune marked an inline comment as done.Dec 27 2020, 12:27 PM
aqjune added inline comments.
llvm/lib/Transforms/Scalar/EarlyCSE.cpp
1078

That was a silly mistake, fixed

aqjune marked an inline comment as done.Dec 27 2020, 12:27 PM
nikic accepted this revision.Dec 27 2020, 12:33 PM

LGTM

This revision is now accepted and ready to land.Dec 27 2020, 12:33 PM
aqjune edited the summary of this revision. (Show Details)Dec 27 2020, 12:36 PM
This revision was landed with ongoing or failed builds.Dec 27 2020, 12:36 PM
This revision was automatically updated to reflect the committed changes.

I'll make another patch for isImpliedCondition , etc at ValueTracking