This is an archive of the discontinued LLVM Phabricator instance.

[NFC][EarlyCSE]Modify test case to ensure branch weights are preserved with cse.
ClosedPublic

Authored by mingmingl on Apr 27 2023, 3:55 PM.

Diff Detail

Event Timeline

mingmingl created this revision.Apr 27 2023, 3:55 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 27 2023, 3:55 PM
mingmingl requested review of this revision.Apr 27 2023, 3:55 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 27 2023, 3:55 PM

How about test cases with PRE of calls? (on the other hand, I think those cases are non trivial to support ).

a = pure_call();
if (cond) {

 b = pure_call();
..

}

>

a = pure_call();
if (cond) {

b = a;

}

and

if (cond) {

b = pure_call();

}
a = pure_call();

>

if (cond) {

t = pure_call();
b = t;

} else {

t = pure_call();

}
a = t;

And LICM case:

for (...) {

sum += pure_call();

}

>

t = pure_call();
for (...) {

sum += t;

}

LICM may drop !prof for a similar reason that !prof is not a known metadata that doesn't have UB side effects (https://github.com/llvm/llvm-project/blob/2dc97921afba741586887037763784fc9b19c304/llvm/lib/Transforms/Scalar/LICM.cpp#L1744) -> so looks like another case to fix.

For one PRE case, both GVN and EarlyCSE could merge call instructions and preserve !prof (https://gcc.godbolt.org/z/3fzP3x6eG and https://gcc.godbolt.org/z/aT8W4crzv)

davidxl accepted this revision.May 1 2023, 9:51 PM

lgtm. Things related LICM etc can be done as followup if there is need.

This revision is now accepted and ready to land.May 1 2023, 9:51 PM

lgtm. Things related LICM etc can be done as followup if there is need.

ack. existing test cases doesn't fail by adding !prof to non undefined-behavior list. I think it could show up in real code (not only artificial test case).

This revision was landed with ongoing or failed builds.May 2 2023, 5:35 PM
This revision was automatically updated to reflect the committed changes.