This is an archive of the discontinued LLVM Phabricator instance.

AMDGPU: Fix handling of constant phi input loop conditions
ClosedPublic

Authored by arsenm on Mar 15 2017, 1:59 PM.

Details

Reviewers
cfang
tstellar
Summary

If the loop condition was an i1 phi with a constantexpr input, this
would add a loop intrinsic fed by a phi dependent on a call to
if.break in the same block. Insert the call in the loop header.

Diff Detail

Event Timeline

arsenm created this revision.Mar 15 2017, 1:59 PM
cfang added inline comments.Mar 15 2017, 2:24 PM
lib/Target/AMDGPU/SIAnnotateControlFlow.cpp
298

Do you think for all constant "Cond" cases, the if.break intrinsics should be inserted to loop header? Not just Cond==BoolTrue?

Initially, we insert in the TERM just to resolve an unhandled assert!

arsenm added inline comments.Mar 15 2017, 2:29 PM
lib/Target/AMDGPU/SIAnnotateControlFlow.cpp
298

It's the opposite. BoolTrue is not inserted into header. Break true is the normal case. The loop before inserts a break rather than an if.break for this case.

I think the way this works is the assumption is the default incoming value is true. phi.broken is filled with 0s for the other predecessors, which with lowering to and_n2 exec, conditionmask is the same as branch true.

cfang accepted this revision.Mar 15 2017, 2:37 PM

LGTM It would be great if you can update the comment:
// Insert IfBreak before TERM for constant COND.

This revision is now accepted and ready to land.Mar 15 2017, 2:37 PM
arsenm closed this revision.Mar 17 2017, 2:04 PM

r298121