This is an archive of the discontinued LLVM Phabricator instance.

[PowerPC] Try to fold sqrt/sdiv test results with the branch.
ClosedPublic

Authored by Esme on Jan 4 2021, 6:19 PM.

Details

Summary

The patch tries to fold sqrt/sdiv test node, i.g FTSQRT, XVTDIVDP, and the branch, i.e br_cc if they satisfy these patterns:

(br_cc seteq, (truncateToi1 SWTestOp), 0) -> (BCC PRED_NU, SWTestOp)
(br_cc seteq, (and Node_test, 2), 0) -> (BCC PRED_NE, PPCNode_test)
(br_cc seteq, (and Node_test, 4), 0) -> (BCC PRED_LE, PPCNode_test)
(br_cc seteq, (and Node_test, 8), 0) -> (BCC PRED_GE, PPCNode_test)
(br_cc setne, (truncateToi1 SWTestOp), 0) -> (BCC PRED_UN, SWTestOp) 
(br_cc setne, (and Node_test, 2), 0) -> (BCC PRED_EQ, PPCNode_test)
(br_cc setne, (and Node_test, 4), 0) -> (BCC PRED_GT, PPCNode_test)
(br_cc setne, (and Node_test, 8), 0) -> (BCC PRED_LT, PPCNode_test)

Diff Detail

Event Timeline

Esme created this revision.Jan 4 2021, 6:19 PM
Esme requested review of this revision.Jan 4 2021, 6:19 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 4 2021, 6:19 PM
steven.zhang added inline comments.Jan 4 2021, 6:44 PM
llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp
4384

Do you have any problems to implement this folding with .td ? It doesn't make sense to me to get the opcode and then do the folding, as that is done during instr match(.td).

Esme updated this revision to Diff 314545.Jan 5 2021, 2:25 AM

Leave the ISel of intrinsics to td.

llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp
4384

These pattens have to be matched before the selection of the single br_cc, which is implemented in PPCISelDAGToDAG.cpp, therefore these folding can't be implemented with .td. You're right, that it'll be better to leave the selection of intrinsics to td.

It seems like this patch depends on another patch. Please don't forget to add the dependencies to the Phabricator reviews.

llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp
4384

If the only possible use for these test nodes are to and the result with 1/2/4, you might as well check the whole thing in this function.
Otherwise, I think it's fine as-is.

4390

Seems odd that a function called isTestSqrtOpcode() returns true for a test for SW divide.

4407

Please add an assert that N is the right type of node (i.e. BR_CC).

4409

It is quite hard to make sense of such huge condition and it aids readability to break it up and name the operands (i.e. CC, CmpLHS, CmpRHS, TgtBlock).

Then you can check the following in order and make it obvious:

  • the RHS is zero
  • the CC is EQ/NE
  • the LHS is (and (testSqrt), imm)
Esme updated this revision to Diff 314805.Jan 5 2021, 11:09 PM

Addressed nemanjai's comments. :)

Esme added a comment.Jan 5 2021, 11:21 PM

It seems like this patch depends on another patch. Please don't forget to add the dependencies to the Phabricator reviews.

An NFC patch, this patch depends on, only committed test cases.

llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp
4384

If the only possible use for these test nodes are to and the result with 1/2/4, you might as well check the whole thing in this function.
Otherwise, I think it's fine as-is.

Another pattern (truncateToi1 SWTestOp) is added now, well, I can't find more possible patterns.

LGTM. Please hold on for days to see if @nemanjai has more comments.

steven.zhang accepted this revision.Jan 11 2021, 6:03 PM
This revision is now accepted and ready to land.Jan 11 2021, 6:03 PM
Esme edited the summary of this revision. (Show Details)Jan 11 2021, 10:05 PM
This revision was landed with ongoing or failed builds.Jan 13 2021, 6:16 PM
This revision was automatically updated to reflect the committed changes.

Thanks for addressing my comments and I'm sorry I didn't get a chance to re-review prior to commit. Looks good now.