This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Fold select based logic of fcmps with same operands when FMF is present.
ClosedPublic

Authored by craig.topper on Mar 9 2022, 11:58 AM.

Details

Summary

If we have a logical and/or in select form and the true/false operand
is an fcmp with poison generating FMF, we won't be able to fold it
to an and/or instruction. This prevents us from optimizing the case
where it is a logical operation of two fcmps with identical operands.

This patch adds explicit checks for this case that doesn't rely on
converting to and/or to do the optimization. It reuses the existing
foldLogicOfFCmps, but adds a new flag to disable the other combine
that is inside that function.

FMF flags from the two FCmps are intersected using the logic added in
D121243. The FIXME has been updated to indicate that we can only use
a union for the non-select form.

This allows us to optimize cases like this from compare-fp-3.c in the
gcc torture suite with fast math.

void
test1 (float x, float y)
{

if ((x==y) && (x!=y))
  link_error0();

}

Diff Detail

Event Timeline

craig.topper created this revision.Mar 9 2022, 11:58 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 9 2022, 11:58 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
craig.topper requested review of this revision.Mar 9 2022, 11:58 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 9 2022, 11:58 AM
khchen added a subscriber: khchen.Mar 10 2022, 4:06 AM
spatel accepted this revision.Mar 14 2022, 2:24 PM

LGTM - in the case of identical predicates and identical operands, EarlyCSE would get it already. It also seems to do an intersection of the FMF for that case.

This revision is now accepted and ready to land.Mar 14 2022, 2:24 PM
This revision was landed with ongoing or failed builds.Mar 14 2022, 2:45 PM
This revision was automatically updated to reflect the committed changes.