Page MenuHomePhabricator

X86 _comi_ intrinsics - Fixed lowering

Authored by delena on Apr 19 2016, 6:05 AM.



Fixed _comi_ intrinsics from all sets - SSE/SSE2/AVX/AVX-512.

_mm_comi*_ss should return false for NaN operands.
_mm_comi_round_ss implemented with VCMPSS. This implementation is not optimal, but correct.
The code will be optimized in a later patch.

Diff Detail


Event Timeline

delena updated this revision to Diff 54181.Apr 19 2016, 6:05 AM
delena retitled this revision from to X86 _comi_ intrinsics - Fixed lowering.
delena updated this object.
delena added reviewers: DavidKreitzer, igorb.
delena set the repository for this revision to rL LLVM.
delena added a subscriber: llvm-commits.

This approach seems fine for now, since it is an improvement over what currently exists. But it seems to me that we would like to unify the handling of the comi intrinsics with the treatment of the FP comparisons in general, at least to the extent possible.


This expansion is overkill for the comparison conditions that can be implemented with a single SETcc. For example, a GT comparison can be implemented with a simple SETA. And an LT comparison can be implemented by reversing operands and using SETA. Only EQ and NEQ need to be implemented with 2 SETcc instructions.

Also, this expansion is incorrect for NEQ. NEQ needs to be implemented as SETNE || SETP.

Fixing these 2 problems will affect the changes you made to the tests, of course.


Did you intend to add this line (in light of a nearly identical line 2)?


Again, did you intend to add this line?


Did you intend to include all these vpmovzx changes in this patch? They look unrelated.

delena updated this revision to Diff 54970.Apr 26 2016, 1:32 AM
delena edited edge metadata.

Fixed comiCC intrinsics according to Dave's comments.

Hi Elena,

You didn't answer my question about the vpmovzx changes. Are they somehow related to the comi changes?



This still isn't quite correct. NaN comparisons will give the wrong results for the [u]comilt and [u]comile intrinsics. They are supposed to behave like the C "<" and "<=" operators, which return false for comparisons involving NaN.

In order to compute _mm_comilt_ss(A, B) with just one SETcc, you need to generate code just like _mm_comigt_ss(B, A).

Did you try running the ex26.c test that I sent you?

delena added inline comments.Apr 27 2016, 2:32 PM

This file is generated by utility. Somebody added printing of vpmovzxbd and it is automatically included now.

delena updated this revision to Diff 55785.May 1 2016, 11:11 PM

Fixed _comilt_* and comile_* lowering.

Hi Elena,

Modulo a few nits, the code changes look good now. Just one additional request for improving the tests.

Also, could you please avoid updating your sources between revisions unless absolutely necessary? That makes it easier for your code reviewers to do incremental reviews. Alternatively, you can post a revision that consists solely of the update. The important things is that reviewers have a way to see just the changes that you've made since the prior revision.



This case is indented incorrectly.


The comment here is a bit misleading, because the code ultimately doesn't check for "ZF,PF,CF <- 001". It would be clearer to write something like "// Reverse operands and check for GT."


Similar comment here.


I like changes you made to test for an explicit operand order for [u]comiss in some places. Could you do that here too and for all the tests where it matters (i.e. gt, ge, lt, and le)? Also for sse2-intrinsics-x86.ll, please.

delena updated this revision to Diff 56150.May 4 2016, 7:46 AM

Fixed comments and tests.

DavidKreitzer accepted this revision.May 4 2016, 8:19 AM
DavidKreitzer edited edge metadata.

Thanks, Elena. LGTM.

This revision is now accepted and ready to land.May 4 2016, 8:19 AM
delena closed this revision.Jun 15 2016, 3:51 AM