This is an archive of the discontinued LLVM Phabricator instance.

[PowerPC] PPC backend optimization on conditional trap intrustions
ClosedPublic

Authored by NeHuang on Oct 8 2021, 9:06 AM.

Details

Summary

This patch adds PPC back end optimization to analyze the arguments of a conditional trap instruction to execute one of the following

  • Delete it if the condition is never true
  • Replace it with an unconditional trap if the condition is always true
  • Otherwise keep it

Diff Detail

Event Timeline

NeHuang created this revision.Oct 8 2021, 9:06 AM
NeHuang requested review of this revision.Oct 8 2021, 9:07 AM
NeHuang updated this revision to Diff 378284.Oct 8 2021, 9:51 AM

clang-format

gentle ping

gentle ping

nemanjai added inline comments.Oct 26 2021, 5:45 AM
llvm/lib/Target/PowerPC/PPCMIPeephole.cpp
1020

Seems that we should be able to handle all 4 in the same block:

  • Check that both operands are LI[8]/LI[S][8]+ORI[8] or an immediate
  • Set the variables for the three constants
  • Determine if this is an unconditional trap or never trap
  • Emit the correct instruction
amyk added inline comments.Oct 26 2021, 7:43 AM
llvm/lib/Target/PowerPC/PPCMIPeephole.cpp
1020

+1

1022

nit: Capitalize and add a period (and for all other comments).

NeHuang updated this revision to Diff 385282.Nov 6 2021, 8:54 AM
NeHuang marked 3 inline comments as done.

Address review comments

amyk added inline comments.Nov 12 2021, 5:50 AM
llvm/lib/Target/PowerPC/PPCMIPeephole.cpp
1027
1029

Do we still need to take into account of the lis+ori that Nemanja mentioned?

1031
1037
nemanjai accepted this revision.Nov 12 2021, 6:49 AM

LGTM. There are some very minor nits that can be addressed on the commit.

llvm/lib/Target/PowerPC/PPCMIPeephole.cpp
1027

Nit: naming convention - variables start with uppercase letters.

1028

I don't understand this comment. You say we can only do the optimization for the "reg + reg" form but the second condition is actually for the "reg + imm" form.

llvm/test/CodeGen/PowerPC/mi-peepholes-trap-opt.mir
6

Please add a couple more tests:

  1. Test case where we delete the instruction because it won't trap
  2. Test case(s) where we do some combination of comparisons (NE(24): <>, LE(20): <=, etc.)
This revision is now accepted and ready to land.Nov 12 2021, 6:49 AM
NeHuang marked 7 inline comments as done.Nov 16 2021, 8:09 AM
NeHuang added inline comments.
llvm/lib/Target/PowerPC/PPCMIPeephole.cpp
1029

IIUC, the optimization will be triggered if the immediate is a s16Immediate. We had the similar check and conversion in this patch https://reviews.llvm.org/D112285

NeHuang marked an inline comment as done.Nov 16 2021, 8:13 AM
NeHuang updated this revision to Diff 387652.Nov 16 2021, 8:15 AM

Addressed review comments

amyk accepted this revision.Nov 16 2021, 8:22 AM

Thanks for addressing the review comments and answering my question. This LGTM.

This revision was landed with ongoing or failed builds.Nov 16 2021, 11:13 AM
This revision was automatically updated to reflect the committed changes.