This is an archive of the discontinued LLVM Phabricator instance.

[SimpleLoopUnswitch] Freeze trivial conditions if needed.
ClosedPublic

Authored by fhahn on Apr 27 2022, 12:21 PM.

Details

Summary

Trivial unswitching can also introduce new branches on undef/poison.
Freeze the conditions if needed.

Diff Detail

Event Timeline

fhahn created this revision.Apr 27 2022, 12:21 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 27 2022, 12:21 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
fhahn requested review of this revision.Apr 27 2022, 12:21 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 27 2022, 12:21 PM
nikic added a subscriber: nikic.
nikic added inline comments.
llvm/test/Transforms/SimpleLoopUnswitch/LIV-loop-condtion.ll
11–12

This freeze doesn't look necessary -- shouldn't there be a "not guaranteed to execute" check involved?

fhahn marked an inline comment as done.Apr 27 2022, 1:13 PM
fhahn added inline comments.
llvm/test/Transforms/SimpleLoopUnswitch/LIV-loop-condtion.ll
11–12

Unfortunately I think the freeze here is needed due to the branch in the loop using %cond.and = and i1 %cond1, %cond2 as branch condition.

%cond1 could be undef and cond2 could always be 0. Then branching on cond1 unconditionally introduces a new branch on undef. (That's not an issue for poison though).

I'd need to check if isGuaranteedNotToBeUndefOrPoison does the right thing if the branch condition isn't an AND/OR but just an invariant value.

fhahn marked an inline comment as done.Apr 27 2022, 1:14 PM
fhahn added inline comments.
llvm/test/Transforms/SimpleLoopUnswitch/LIV-loop-condtion.ll
11–12
nikic added inline comments.Apr 27 2022, 1:17 PM
llvm/test/Transforms/SimpleLoopUnswitch/LIV-loop-condtion.ll
11–12

Oh right, forgot about the undef case. That's annoying.

nikic accepted this revision.Apr 28 2022, 6:23 AM

LGTM

This revision is now accepted and ready to land.Apr 28 2022, 6:23 AM
fhahn updated this revision to Diff 426242.Apr 30 2022, 11:51 AM

Rebase so it can be applied before D124526.

This revision was landed with ongoing or failed builds.Apr 30 2022, 11:54 AM
This revision was automatically updated to reflect the committed changes.