This is an archive of the discontinued LLVM Phabricator instance.

[TargetLowering] Fix what look like copy/paste mistakes in compare with infinity handling SimplifySetCC.
ClosedPublic

Authored by craig.topper on Mar 1 2020, 11:27 PM.

Details

Summary

I expect that the isCondCodeLegal checks should match that CC of
the node that we're going to create.

Diff Detail

Event Timeline

craig.topper created this revision.Mar 1 2020, 11:27 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 1 2020, 11:27 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
spatel added a comment.Mar 2 2020, 5:35 AM

Looks like a good fix, but I think it would be better to use switch/case on these to reduce the duplication. Something like (make sure this matches the existing logic):

bool IsNegInf = CFP->getValueAPF().isNegative();
ISD::CondCode NewCond;
switch (Cond) {
// X == -Inf --> X <= -Inf or X == Inf --> X >= Inf
case ISD::SETOEQ: NewCond = IsNegInf ? ISD::SETOLE : ISD::SETOGE; break;
case ISD::SETUEQ: NewCond = IsNegInf ? ISD::SETULE : ISD::SETUGE; break;
// X != -Inf --> X > -Inf or X != Inf --> X < Inf
case ISD::SETONE: NewCond = IsNegInf ? ISD::SETOGT : ISD::SETOLT; break;
case ISD::SETUNE: NewCond = IsNegInf ? ISD::SETUGT : ISD::SETULT; break;
default: NewCond = ISD::SETCC_INVALID; break;
}
if (NewCond != ISD::SETCC_INVALID &&
    isCondCodeLegal(NewCond, N0.getSimpleValueType()))
  return DAG.getSetCC(dl, VT, N0, N1, NewCond);

Rewrite using a switch

spatel accepted this revision.Mar 2 2020, 1:23 PM

LGTM

This revision is now accepted and ready to land.Mar 2 2020, 1:23 PM