This is an archive of the discontinued LLVM Phabricator instance.

[PowerPC] Do not attempt to reuse load for 64-bit FP_TO_UINT without FPCVT
ClosedPublic

Authored by nemanjai on Apr 6 2020, 9:00 AM.

Details

Summary

We call the function that attempts to reuse the conversion without checking whether the target matches the constraints that the callee expects. This patch adds the check prior to the call.

Fixes: https://bugs.llvm.org/show_bug.cgi?id=43976

Diff Detail

Event Timeline

nemanjai created this revision.Apr 6 2020, 9:00 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 6 2020, 9:00 AM

run clang-format, but otherwise for fixing the assertion it LGTM. FWIW I'm not sure the code we produce for the conversion handles negative numbers correctly. For the reduced IR I posted I get:

# %bb.0:                                # %entry
        addis 3, 2, .LCPI0_0@toc@ha
        li 4, 1
        lfs 0, .LCPI0_0@toc@l(3)
        sldi 4, 4, 63
        fsub 2, 1, 0
        fctidz 2, 2
        stfd 2, -8(1)
        fctidz 2, 1
        stfd 2, -16(1)
        ld 3, -8(1)
        ld 5, -16(1)
        fcmpu 0, 1, 0
        xor 3, 3, 4
        bc 12, 0, .LBB0_1
        b .LBB0_2
.LBB0_1:                                # %entry
        addi 3, 5, 0
.LBB0_2:                                # %entry
        std 3, -24(1)
        lfd 0, -24(1)
        fcfid 1, 0
        blr

Which I think mishandles negative values. I cant produce the same output on powerpc64le so I haven't tested it yet, but will try on AIX64 to see if the assembly works like I think it does.

llvm/test/CodeGen/PowerPC/pr43976.ll
5

We can reduce the test further and still exercise the assertion:

define dso_local double @b(double) local_unnamed_addr {
entry:
  %conv = fptoui double %0 to i64
  %conv1 = sitofp i64 %conv to double
  ret double %conv1
}
sfertile accepted this revision as: sfertile.Apr 6 2020, 2:07 PM

Which I think mishandles negative values.

I was wrong. Thanks Nemanja for testing it out on a BE machine for me.

This revision is now accepted and ready to land.Apr 6 2020, 2:07 PM
pkubaj added a subscriber: pkubaj.Apr 17 2020, 4:06 AM

Is there anything preventing this from being committed?
If you can, please also backport for 10.0.1.
Thanks!

nemanjai marked an inline comment as done.Apr 20 2020, 8:26 AM
nemanjai added inline comments.
llvm/test/CodeGen/PowerPC/pr43976.ll
5

I initially reduced this down to something like that, but chose not to go ahead with that for two reasons:

  1. The test case in the PR is simple enough and I wanted the test case to actually represent the reported test
  2. I am not sure if some DAG combine in the future might fold the operations into something different
This revision was automatically updated to reflect the committed changes.