This is an archive of the discontinued LLVM Phabricator instance.

[PowerPC] Legalize SETULT and SETUGT for type f32 and f64.
Needs RevisionPublic

Authored by jtony on Jan 16 2018, 6:43 AM.

Details

Summary

ISD::SETULT and ISD::SETUGT for type f32 and f64 on PowerPC are currently set to Expand. They are legalized in this patch.

Diff Detail

Event Timeline

jtony created this revision.Jan 16 2018, 6:43 AM
nemanjai requested changes to this revision.Jan 25 2018, 2:09 PM
nemanjai added inline comments.
lib/Target/PowerPC/PPCISelDAGToDAG.cpp
3521

I don't think this is safe to just overlook. Sure the comment doesn't apply any more, but the solution does not appear to be to just remove the comment. You'll have to see where the enclosing function is called and what assumptions are based on us not having FP here.
At the very least, one example shows that we'll have a miscompile due to this:

define double @test(double %a, double %b, double %c, double %d) {
entry:
  %cmp = fcmp ult double %a, %b
  %cond = select i1 %cmp, double %c, double %d
  ret double %cond
}

That'll produce a SET_CC_VSFRC from the ISD::SELECT_CC and the predicate will be PPC::PRED_LT. Of course, that won't consider the UN bit. And sure enough, it'll produce the following code:

xscmpudp 0, 1, 2
blt     0, .LBB0_2

when it should actually be producing:

xscmpudp 0, 1, 2
cror 20, 0, 3
bc 12, 20, .LBB0_2
This revision now requires changes to proceed.Jan 25 2018, 2:09 PM
jtony added inline comments.Jan 26 2018, 12:30 PM
lib/Target/PowerPC/PPCISelDAGToDAG.cpp
3521

That's a very good catch. I am trying to figure out how we should fix this wrong code-gen here. BTW, one minor nit in the comment: the code you provided will actually produce a SELECT_CC_VSFRC from the ISD::SELECT_CC (we don't have SET_CC_VSFRC)