[PATCH] D29729: [InstCombine] don't lose nsw/nuw from add by converting to xor
Sanjay Patel via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Feb 11 10:21:37 PST 2017
spatel updated this revision to Diff 88097.
spatel added a comment.
Patch updated:
If llvm.assume can't be used to solve this, I don't know of an existing way to do it, so I'm making this an NFC documentation patch for the current behavior.
https://reviews.llvm.org/D29729
Files:
lib/Transforms/InstCombine/InstCombineAddSub.cpp
test/Transforms/InstCombine/add.ll
test/Transforms/InstCombine/icmp-add.ll
Index: test/Transforms/InstCombine/icmp-add.ll
===================================================================
--- test/Transforms/InstCombine/icmp-add.ll
+++ test/Transforms/InstCombine/icmp-add.ll
@@ -229,7 +229,8 @@
ret i1 %c
}
-; FIXME: InstCombine should not lose wrapping information by changing the add to xor.
+; This is known 'true', but we canonicalize the add to xor and lose that information.
+; Metadata that preserves the nsw-ness of the add could be used to improve this.
define i1 @slt_zero_add_nsw_signbit(i8 %x) {
; CHECK-LABEL: @slt_zero_add_nsw_signbit(
@@ -241,7 +242,8 @@
ret i1 %z
}
-; FIXME: InstCombine should not lose wrapping information by changing the add to xor.
+; This is known 'true', but we canonicalize the add to xor and lose that information.
+; Metadata that preserves the nuw-ness of the add could be used to improve this.
define i1 @slt_zero_add_nuw_signbit(i8 %x) {
; CHECK-LABEL: @slt_zero_add_nuw_signbit(
Index: test/Transforms/InstCombine/add.ll
===================================================================
--- test/Transforms/InstCombine/add.ll
+++ test/Transforms/InstCombine/add.ll
@@ -265,7 +265,7 @@
ret i32 %add
}
-; Lose no-wrap info by converting to xor? %x is known non-negative
+; Lose no-wrap info by converting to xor. %x is known non-negative
; here, but not after converting to xor.
define i8 @add_nsw_signbit(i8 %x) {
@@ -277,7 +277,7 @@
ret i8 %y
}
-; Lose no-wrap info by converting to xor? %x is known non-negative
+; Lose no-wrap info by converting to xor. %x is known non-negative
; (x < 128 unsigned), but not after converting to xor.
define i8 @add_nuw_signbit(i8 %x) {
Index: lib/Transforms/InstCombine/InstCombineAddSub.cpp
===================================================================
--- lib/Transforms/InstCombine/InstCombineAddSub.cpp
+++ lib/Transforms/InstCombine/InstCombineAddSub.cpp
@@ -1044,7 +1044,9 @@
const APInt *Val;
if (match(RHS, m_APInt(Val))) {
- // X + (signbit) --> X ^ signbit
+ // X + (signbit) --> X ^ signbit. We may drop nsw/nuw here and forgo
+ // optimizations based on that.
+ // TODO: We could add metadata to preserve the wrapping information?
if (Val->isSignBit())
return BinaryOperator::CreateXor(LHS, RHS);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29729.88097.patch
Type: text/x-patch
Size: 2304 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170211/bc0494f5/attachment.bin>
More information about the llvm-commits
mailing list