This is an archive of the discontinued LLVM Phabricator instance.

Correct instcombine of fcmp+select.
Needs ReviewPublic

Authored by csigg on Jan 25 2022, 4:46 AM.

Details

Reviewers
spatel
Summary
  1. Zero fcmp arguments were previously replaced with zero select arguments without considering or adjusting the predicate. However, without no-signed-zeros, only the following are equivalent:
   >= +0  <=>     > -0
   <= -0  <=>     < +0
-0 >=     <=>  +0 >
+0 <=     <=>  -0 <
  1. Combining fcmp+select into fminnum is not permitted when the arguments might be two zeros of opposite sign. E.g., fminnum(-0, +0) can return any of the two operands and is therefore not equivalent to '-0 < +0 ? -0 : +0'. This was handled for >= and <= but marked as 'FIXME' for > and <.
  1. fminimum does treat -0 as smaller than +0, so fcmp+select can be combined if the NaN-propagating bahaviour of fminimum is permitted. Previously, the handling of signed zeros applied to combining fcmp+select into both fminnum and fminimum.

The same applies for fmaxnum/fmaximum.

Hopefully 3) can make up for the performance lost by fixing 1) and 2).

Diff Detail

Event Timeline

csigg created this revision.Jan 25 2022, 4:46 AM
csigg requested review of this revision.Jan 25 2022, 4:46 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 25 2022, 4:46 AM
csigg updated this revision to Diff 403571.Jan 27 2022, 3:14 AM

Rebase.

csigg updated this revision to Diff 459756.Sep 13 2022, 8:19 AM

Rebase.

Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptSep 13 2022, 8:19 AM

Something has gone wrong with the diff.

Sorry - I didn't remember this patch when I was looking at a bug fix with:
4e44c22c97be

We may need more unit and/or IR tests to verify that we are getting the correct results for all of these patterns.

Something has gone wrong with the diff.

Very much so, I rebased the wrong diff :-(

Let me try to resurrect it.

csigg updated this revision to Diff 459819.Sep 13 2022, 11:11 AM

Restore diff.

Restore diff.

Still need to update to account for the changes 4e44c22c97be?