[PATCH] D128123: [SDAG] try to replace subtract-from-constant with xor
Sanjay Patel via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 12 09:14:29 PDT 2022
spatel added a comment.
In D128123#3645509 <https://reviews.llvm.org/D128123#3645509>, @foad wrote:
> If there's no chance any bit will need to borrow from an adjacent bit then there is no unsigned wrap by definition, so I'm not sure losing the nuw flag would actually lose any information.
Yes, good point. That suggests that we should also improve later passes to recognize xor as sub when profitable.
The test that I was looking where I don't think we can recover is:
define i1 @test_negative_combined_sub_signed_overflow(i8 %x) {
; CHECK-LABEL: @test_negative_combined_sub_signed_overflow(
; CHECK-NEXT: ret i1 false
;
%y = sub nsw i8 127, %x
%z = icmp slt i8 %y, -1
ret i1 %z
}
If we convert that to xor (after applying the equivalent of the SDAG patch in d0eec5f7e787 <https://reviews.llvm.org/rGd0eec5f7e7874ecfdface473cd4718ac5e6e629e>), then we would have:
%y = xor i8 %x, 127
%z = icmp slt i8 %y, -1
And now we can't fold the whole thing to 'false' anymore.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D128123/new/
https://reviews.llvm.org/D128123
More information about the llvm-commits
mailing list