This is an archive of the discontinued LLVM Phabricator instance.

[PowerPC] swdiv builtins for XL compatibility
ClosedPublic

Authored by quinnp on Jul 28 2021, 7:22 AM.

Details

Reviewers
nemanjai
stefanp
Group Reviewers
Restricted Project
Commits
rG67a3d1e27551: [PowerPC] swdiv builtins for XL compatibility
Summary

This patch is in a series of patches to provide builtins for compatibility with
the XL compiler. This patch implements the software divide builtin as
wrappers for a floating point divide. XL provided these builtins because it
didn't produce software estimates by default at -Ofast. When compiled
with -Ofast these builtins will produce the software estimate for divide.

Diff Detail

Event Timeline

quinnp created this revision.Jul 28 2021, 7:22 AM
quinnp requested review of this revision.Jul 28 2021, 7:22 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJul 28 2021, 7:22 AM
quinnp added reviewers: Restricted Project, nemanjai, stefanp.Jul 28 2021, 7:25 AM
quinnp retitled this revision from [PowerPC] swdiv builtins for XL compatibility] to [PowerPC] swdiv builtins for XL compatibility.
quinnp updated this revision to Diff 362400.Jul 28 2021, 8:28 AM

Fixing a failing test case.

efriedma added inline comments.
llvm/test/CodeGen/PowerPC/LowerCheckedFPArith.ll
36 ↗(On Diff #362400)

A "fast" fdiv never produces NaN, per LangRef. Using fcmp like this is fragile at best.

(Maybe you want "fdiv arcp"?)

NeHuang added inline comments.
llvm/test/CodeGen/PowerPC/O3-pipeline.ll
211 ↗(On Diff #362400)

unrelated change?

llvm/test/CodeGen/PowerPC/int-ppc-ftdivdp.ll
7 ↗(On Diff #362400)

nit: pwr7 for aix run lines

8 ↗(On Diff #362400)

can we also add a run line for 64 bit AIX?

quinnp updated this revision to Diff 363189.Jul 30 2021, 1:12 PM

Addressing review comments.

quinnp marked 3 inline comments as done.Jul 30 2021, 1:13 PM
quinnp marked an inline comment as done.Jul 30 2021, 1:26 PM
quinnp added inline comments.
llvm/test/CodeGen/PowerPC/LowerCheckedFPArith.ll
36 ↗(On Diff #362400)

Thank you, I see what you mean. I have changed it to emit a fdiv ninf arcp instead of a fdiv fast. I included the ninf flag because without it the compiler doesn't produce the software div estimate.

quinnp marked an inline comment as done.Jul 30 2021, 1:29 PM
efriedma added inline comments.Jul 30 2021, 1:39 PM
llvm/test/CodeGen/PowerPC/LowerCheckedFPArith.ll
36 ↗(On Diff #362400)

ninf is also an issue, although maybe less likely to bite in practice. Consider what happens if someone passes infinity to swdivs: the fdiv reduces to poison, so the branch is undefined behavior.

amyk added a subscriber: amyk.Jul 30 2021, 3:03 PM
amyk added inline comments.
llvm/include/llvm/IR/IntrinsicsPowerPC.td
1436 ↗(On Diff #363189)

Line too long?

1724 ↗(On Diff #363189)

Minor indentation nit.

1727 ↗(On Diff #363189)

Minor indentation nit.

llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
451 ↗(On Diff #363189)

Nit: Add a comment before creating the pass as the other pass calls also follow a comment.

NeHuang added inline comments.Aug 6 2021, 9:15 AM
clang/test/CodeGen/builtins-ppc-xlcompat-swdiv.c
18

nit: alignment with CHECKs below. Same for the other test cases.

llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
452 ↗(On Diff #363189)

+1,

quinnp updated this revision to Diff 374847.EditedSep 24 2021, 7:35 AM
quinnp marked 7 inline comments as done.

Updating the patch to emit a fdiv for each of the builtins without any fast math flags. This will be safe and will still emit a software estimate when -Ofast is used.

llvm/test/CodeGen/PowerPC/LowerCheckedFPArith.ll
36 ↗(On Diff #362400)

We've decided to emit an fdiv without any fast math flags for these builtins. This will be safe and will emit the software estimate for -Ofast.

quinnp edited the summary of this revision. (Show Details)Sep 24 2021, 7:39 AM

Do we already have a backend test case for fdiv emitting a software estimate when -Ofast is used?

quinnp updated this revision to Diff 375285.Sep 27 2021, 8:35 AM

Added a backend testcase which goes from fdiv fast to software estimate. Added a runline in the front end testcase that sets the fast math flags.

Do we already have a backend test case for fdiv emitting a software estimate when -Ofast is used?

I've added a testcase in llvm/test/CodeGen/PowerPC/fdiv.ll which goes from fdiv fast to the assembly for the software divide estimate.

nemanjai accepted this revision.Sep 28 2021, 6:27 PM

LGTM. Please note in the commit message that this is simply a wrapper for a floating point divide. XL provided this builtin because it doesn't produce software estimates by default at -Ofast.

This revision is now accepted and ready to land.Sep 28 2021, 6:27 PM
quinnp edited the summary of this revision. (Show Details)Sep 28 2021, 8:38 PM
quinnp edited the summary of this revision. (Show Details)Sep 28 2021, 8:41 PM
quinnp edited the summary of this revision. (Show Details)
quinnp updated this revision to Diff 375912.Sep 29 2021, 8:55 AM

Fixing failing test case after rebasing with https://reviews.llvm.org/D110213.

This revision was landed with ongoing or failed builds.Sep 29 2021, 9:31 AM
This revision was automatically updated to reflect the committed changes.