This is an archive of the discontinued LLVM Phabricator instance.

[Legalizer] Avoid expansion to BR_CC if illegal
ClosedPublic

Authored by qiucf on Sep 28 2021, 2:25 AM.

Details

Summary

Per discussion in D92083, the legalizer needs to handle such cases.

Diff Detail

Event Timeline

qiucf created this revision.Sep 28 2021, 2:25 AM
qiucf requested review of this revision.Sep 28 2021, 2:25 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 28 2021, 2:25 AM
qiucf edited the summary of this revision. (Show Details)Sep 28 2021, 2:28 AM
pengfei added inline comments.Sep 28 2021, 2:36 AM
llvm/test/CodeGen/PowerPC/f128-branch-cond.ll
5

Missing the check contents?

qiucf updated this revision to Diff 375504.Sep 28 2021, 2:38 AM
qiucf marked an inline comment as done.

LGTM - any other comments?

shchenz added a subscriber: shchenz.Nov 7 2021, 5:44 PM
shchenz added inline comments.
llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
3714

Just curious, will it be possible that the new BR_CC is still not legalized? And thus leading to an infinite loop here?

If I'm reading the debug logs right, we started from a BRCOND with a SETCC input, the was expanded to an unsupported BR_CC. So now we need to expand the BR_CC. Should we have just checked for BR_CC legality before expanding the BRCOND using BR_CC?

qiucf updated this revision to Diff 387154.Nov 14 2021, 9:03 PM

Prevent BR_CC to be generated unless it's legal or custom

craig.topper added inline comments.Nov 16 2021, 4:34 PM
llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
3562

Why did the push_backs need to be moved?

llvm/test/CodeGen/PowerPC/f128-branch-cond.ll
8

Add nounwind attribute to these test cases to get rid of the .cfi* directives

qiucf updated this revision to Diff 387816.Nov 16 2021, 8:34 PM
qiucf marked an inline comment as done.
qiucf added inline comments.
llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
3562

Here when BR_CC is not legal, Results should be empty.

craig.topper added inline comments.Nov 16 2021, 8:43 PM
llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
3562

If it's not legal, won't we go to the else which will always push something to Results?

qiucf updated this revision to Diff 387869.Nov 17 2021, 1:24 AM
qiucf retitled this revision from [Legalizer] Expand BR_CC into SETCC if condition code is legal to [Legalizer] Avoid expansion to BR_CC if illegal.
shchenz accepted this revision.Nov 23 2021, 9:24 PM

Thanks. LGTM. Please hold on some days in case other reviewers like @craig.topper have further comments.

This revision is now accepted and ready to land.Nov 23 2021, 9:24 PM
craig.topper added inline comments.Nov 24 2021, 9:12 AM
llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
3558

I think we need to go to the else case. We shouldn't leave this function without pushing something to the Results vector. Anything that doesn't push to the Results vector, will try libcall expansion. But there is no libcall for BRCOND so we fail that too. The debug log contains these messages

Trying to expand node                                                            
Cannot expand node                                                               
Trying to convert node to libcall                                                
Could not convert node to libcall

I think after that the BRCOND will stick around even though it isn't "legal". After that the SETCC gets letalized to a SELECT_CC. Once we leave op legalization, the last DAG combine runs. That will call back into this function to try to legalize the still illegal BRCOND. The input is no longer a SETCC so it falls to the else case here which finally legalizes it.

We should have just gone to the else the first time. It's creating a BR_CC on i32 not on fp128 so it should be fine.

craig.topper requested changes to this revision.Nov 24 2021, 11:22 AM
This revision now requires changes to proceed.Nov 24 2021, 11:22 AM
qiucf updated this revision to Diff 390880.Nov 30 2021, 6:41 PM
qiucf marked an inline comment as done.
qiucf set the repository for this revision to rG LLVM Github Monorepo.

Fall into else when illegal

This revision is now accepted and ready to land.Nov 30 2021, 6:43 PM
This revision was automatically updated to reflect the committed changes.