-
Notifications
You must be signed in to change notification settings - Fork 183
[CIR][Lowering] Fix Vector Comparison Lowering with -fno-signed-char/unsigned operand #1770
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
We just went through a rebase, this PR needs to be updated. |
827f592 to
e040553
Compare
Updated this along with my other currently open PR's |
|
|
e040553 to
06b0af0
Compare
My apologies. Tests seems to be fixed now. I'm still waiting for your follow up on the discussion above in order to push forward this PR if required. Thanks 😃 |
Three things: - Corrected comments to `getZeroInitAttr` as [we return more than only integrals in that function](https://github.com/llvm/clangir/blob/2ea4005fa0aa291295b19c200860b5edf9b864b3/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h#L133). - Given that `emitX86MaskedCompare` and `emitX86MaskedCompareResult` helpers are pretty large, Added NYI statements on paths not related to the current set of intrinsics so review is specific to the ones encoded. - Added test comments related to the behavior observed coming from the canonicalizer on: #1770
Three things: - Corrected comments to `getZeroInitAttr` as [we return more than only integrals in that function](https://github.com/llvm/clangir/blob/2ea4005fa0aa291295b19c200860b5edf9b864b3/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h#L133). - Given that `emitX86MaskedCompare` and `emitX86MaskedCompareResult` helpers are pretty large, Added NYI statements on paths not related to the current set of intrinsics so review is specific to the ones encoded. - Added test comments related to the behavior observed coming from the canonicalizer on: llvm#1770
While working on _mm_movepi8_mask, intrinsic (and similar sign-bit checking intrinsics containing 8-bit integers) was being optimized away when using -fno-signed-char. Effectively replacing a cmp expression for 0.
Since unsigned values can never be less than zero, the CIR lowering was directly generating a constant 0 (I suppose we fold a vec filled with 0's to our target, which is a scalar mask, which in turn is 0) instead of the intended comparison operation, completely eliminating the icmp instruction.
See when passing as arg -fno-signed-char (no cmp generated):
OG:
CIR:
Since integer signedness is something we can track, the behaviour CIR is enforcing makes sense; however, if we want to preserve parity with OG, I believe this patch will match that. I can close this PR if that's not applicable to this case.
Added special case detection for sign-bit extraction patterns (lt comparison with cir::ZeroAttr) to force signed comparison regardless of the element type's signedness. This preserves the semantic intent of checking sign bits rather than performing mathematical unsigned comparisons.