summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/test/Transforms/InstSimplify/result-of-add-of-negative-is-non-zero-and-no-underflow.ll24
-rw-r--r--llvm/test/Transforms/InstSimplify/result-of-usub-is-non-zero-and-no-overflow.ll44
2 files changed, 68 insertions, 0 deletions
diff --git a/llvm/test/Transforms/InstSimplify/result-of-add-of-negative-is-non-zero-and-no-underflow.ll b/llvm/test/Transforms/InstSimplify/result-of-add-of-negative-is-non-zero-and-no-underflow.ll
index 58a56c4d7ba..9521a71bd70 100644
--- a/llvm/test/Transforms/InstSimplify/result-of-add-of-negative-is-non-zero-and-no-underflow.ll
+++ b/llvm/test/Transforms/InstSimplify/result-of-add-of-negative-is-non-zero-and-no-underflow.ll
@@ -99,3 +99,27 @@ define i1 @t4_commutative(i8 %base, i8 %offset) {
%r = and i1 %not_null, %no_underflow
ret i1 %r
}
+
+; We only need to know that any of the 'add' operands is non-zero,
+; not necessarily the one used in the comparison.
+define i1 @t5(i8 %base, i8 %offset) {
+; CHECK-LABEL: @t5(
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[OFFSET:%.*]], 0
+; CHECK-NEXT: call void @llvm.assume(i1 [[CMP]])
+; CHECK-NEXT: [[ADJUSTED:%.*]] = add i8 [[BASE:%.*]], [[OFFSET]]
+; CHECK-NEXT: call void @use8(i8 [[ADJUSTED]])
+; CHECK-NEXT: [[NOT_NULL:%.*]] = icmp ne i8 [[ADJUSTED]], 0
+; CHECK-NEXT: [[NO_UNDERFLOW:%.*]] = icmp ult i8 [[ADJUSTED]], [[BASE]]
+; CHECK-NEXT: [[R:%.*]] = or i1 [[NOT_NULL]], [[NO_UNDERFLOW]]
+; CHECK-NEXT: ret i1 [[R]]
+;
+ %cmp = icmp slt i8 %offset, 0
+ call void @llvm.assume(i1 %cmp)
+
+ %adjusted = add i8 %base, %offset
+ call void @use8(i8 %adjusted)
+ %not_null = icmp ne i8 %adjusted, 0
+ %no_underflow = icmp ult i8 %adjusted, %base
+ %r = or i1 %not_null, %no_underflow
+ ret i1 %r
+}
diff --git a/llvm/test/Transforms/InstSimplify/result-of-usub-is-non-zero-and-no-overflow.ll b/llvm/test/Transforms/InstSimplify/result-of-usub-is-non-zero-and-no-overflow.ll
index 66ff797c252..fcc48310951 100644
--- a/llvm/test/Transforms/InstSimplify/result-of-usub-is-non-zero-and-no-overflow.ll
+++ b/llvm/test/Transforms/InstSimplify/result-of-usub-is-non-zero-and-no-overflow.ll
@@ -138,3 +138,47 @@ define i1 @t2_commutativity(i8 %base, i8 %offset) {
%r = and i1 %null, %underflow
ret i1 %r
}
+
+; Overflow OR not zero => always true
+define i1 @t3(i8 %base, i8 %offset) {
+; CHECK-LABEL: @t3(
+; CHECK-NEXT: [[ADJUSTED:%.*]] = sub i8 [[BASE:%.*]], [[OFFSET:%.*]]
+; CHECK-NEXT: call void @use8(i8 [[ADJUSTED]])
+; CHECK-NEXT: [[NO_UNDERFLOW:%.*]] = icmp ule i8 [[BASE]], [[OFFSET]]
+; CHECK-NEXT: call void @use1(i1 [[NO_UNDERFLOW]])
+; CHECK-NEXT: [[NOT_NULL:%.*]] = icmp ne i8 [[ADJUSTED]], 0
+; CHECK-NEXT: call void @use1(i1 [[NOT_NULL]])
+; CHECK-NEXT: [[R:%.*]] = or i1 [[NOT_NULL]], [[NO_UNDERFLOW]]
+; CHECK-NEXT: ret i1 [[R]]
+;
+ %adjusted = sub i8 %base, %offset
+ call void @use8(i8 %adjusted)
+ %no_underflow = icmp ule i8 %base, %offset
+ call void @use1(i1 %no_underflow)
+ %not_null = icmp ne i8 %adjusted, 0
+ call void @use1(i1 %not_null)
+ %r = or i1 %not_null, %no_underflow
+ ret i1 %r
+}
+
+; No overflow and zero => always false
+define i1 @t4(i8 %base, i8 %offset) {
+; CHECK-LABEL: @t4(
+; CHECK-NEXT: [[ADJUSTED:%.*]] = sub i8 [[BASE:%.*]], [[OFFSET:%.*]]
+; CHECK-NEXT: call void @use8(i8 [[ADJUSTED]])
+; CHECK-NEXT: [[NO_UNDERFLOW:%.*]] = icmp ugt i8 [[BASE]], [[OFFSET]]
+; CHECK-NEXT: call void @use1(i1 [[NO_UNDERFLOW]])
+; CHECK-NEXT: [[NOT_NULL:%.*]] = icmp eq i8 [[ADJUSTED]], 0
+; CHECK-NEXT: call void @use1(i1 [[NOT_NULL]])
+; CHECK-NEXT: [[R:%.*]] = and i1 [[NOT_NULL]], [[NO_UNDERFLOW]]
+; CHECK-NEXT: ret i1 [[R]]
+;
+ %adjusted = sub i8 %base, %offset
+ call void @use8(i8 %adjusted)
+ %no_underflow = icmp ugt i8 %base, %offset
+ call void @use1(i1 %no_underflow)
+ %not_null = icmp eq i8 %adjusted, 0
+ call void @use1(i1 %not_null)
+ %r = and i1 %not_null, %no_underflow
+ ret i1 %r
+}
OpenPOWER on IntegriCloud