[llvm] 0315571 - [InstCombine] add tests for icmp with mul nsw/nuw; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 5 14:30:37 PDT 2020
Author: Sanjay Patel
Date: 2020-08-05T17:07:22-04:00
New Revision: 0315571a19bb27da1b68088b07f1368747dd9438
URL: https://github.com/llvm/llvm-project/commit/0315571a19bb27da1b68088b07f1368747dd9438
DIFF: https://github.com/llvm/llvm-project/commit/0315571a19bb27da1b68088b07f1368747dd9438.diff
LOG: [InstCombine] add tests for icmp with mul nsw/nuw; NFC
Added:
Modified:
llvm/test/Transforms/InstCombine/icmp-mul.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/InstCombine/icmp-mul.ll b/llvm/test/Transforms/InstCombine/icmp-mul.ll
index 24709a235baa..45c50c325b96 100644
--- a/llvm/test/Transforms/InstCombine/icmp-mul.ll
+++ b/llvm/test/Transforms/InstCombine/icmp-mul.ll
@@ -1,6 +1,8 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -instcombine -S | FileCheck %s
+declare void @use(i8)
+
; Tests for slt/ult
define i1 @slt_positive_multip_rem_zero(i8 %x) {
@@ -117,43 +119,161 @@ define i1 @ugt_rem_nz(i8 %x) {
; Tests for eq/ne
-define i1 @eq_rem_zero(i8 %x) {
-; CHECK-LABEL: @eq_rem_zero(
-; CHECK-NEXT: [[A:%.*]] = mul nuw i8 [[X:%.*]], 5
+define i1 @eq_nsw_rem_zero(i8 %x) {
+; CHECK-LABEL: @eq_nsw_rem_zero(
+; CHECK-NEXT: [[A:%.*]] = mul nsw i8 [[X:%.*]], -5
; CHECK-NEXT: [[B:%.*]] = icmp eq i8 [[A]], 20
; CHECK-NEXT: ret i1 [[B]]
;
- %a = mul nuw i8 %x, 5
+ %a = mul nsw i8 %x, -5
+ %b = icmp eq i8 %a, 20
+ ret i1 %b
+}
+
+define <2 x i1> @ne_nsw_rem_zero(<2 x i8> %x) {
+; CHECK-LABEL: @ne_nsw_rem_zero(
+; CHECK-NEXT: [[A:%.*]] = mul nsw <2 x i8> [[X:%.*]], <i8 5, i8 5>
+; CHECK-NEXT: [[B:%.*]] = icmp ne <2 x i8> [[A]], <i8 -30, i8 -30>
+; CHECK-NEXT: ret <2 x i1> [[B]]
+;
+ %a = mul nsw <2 x i8> %x, <i8 5, i8 5>
+ %b = icmp ne <2 x i8> %a, <i8 -30, i8 -30>
+ ret <2 x i1> %b
+}
+
+define <2 x i1> @ne_nsw_rem_zero_undef1(<2 x i8> %x) {
+; CHECK-LABEL: @ne_nsw_rem_zero_undef1(
+; CHECK-NEXT: [[A:%.*]] = mul nsw <2 x i8> [[X:%.*]], <i8 5, i8 undef>
+; CHECK-NEXT: [[B:%.*]] = icmp ne <2 x i8> [[A]], <i8 -30, i8 -30>
+; CHECK-NEXT: ret <2 x i1> [[B]]
+;
+ %a = mul nsw <2 x i8> %x, <i8 5, i8 undef>
+ %b = icmp ne <2 x i8> %a, <i8 -30, i8 -30>
+ ret <2 x i1> %b
+}
+
+define <2 x i1> @ne_nsw_rem_zero_undef2(<2 x i8> %x) {
+; CHECK-LABEL: @ne_nsw_rem_zero_undef2(
+; CHECK-NEXT: [[A:%.*]] = mul nsw <2 x i8> [[X:%.*]], <i8 5, i8 5>
+; CHECK-NEXT: [[B:%.*]] = icmp ne <2 x i8> [[A]], <i8 -30, i8 undef>
+; CHECK-NEXT: ret <2 x i1> [[B]]
+;
+ %a = mul nsw <2 x i8> %x, <i8 5, i8 5>
+ %b = icmp ne <2 x i8> %a, <i8 -30, i8 undef>
+ ret <2 x i1> %b
+}
+
+define i1 @eq_nsw_rem_zero_uses(i8 %x) {
+; CHECK-LABEL: @eq_nsw_rem_zero_uses(
+; CHECK-NEXT: [[A:%.*]] = mul nsw i8 [[X:%.*]], -5
+; CHECK-NEXT: call void @use(i8 [[A]])
+; CHECK-NEXT: [[B:%.*]] = icmp eq i8 [[A]], 20
+; CHECK-NEXT: ret i1 [[B]]
+;
+ %a = mul nsw i8 %x, -5
+ call void @use(i8 %a)
%b = icmp eq i8 %a, 20
ret i1 %b
}
-define i1 @ne_rem_zero(i8 %x) {
-; CHECK-LABEL: @ne_rem_zero(
+; Impossible multiple should be handled by instsimplify.
+
+define i1 @eq_nsw_rem_nz(i8 %x) {
+; CHECK-LABEL: @eq_nsw_rem_nz(
+; CHECK-NEXT: ret i1 false
+;
+ %a = mul nsw i8 %x, 5
+ %b = icmp eq i8 %a, 245
+ ret i1 %b
+}
+
+; Impossible multiple should be handled by instsimplify.
+
+define i1 @ne_nsw_rem_nz(i8 %x) {
+; CHECK-LABEL: @ne_nsw_rem_nz(
+; CHECK-NEXT: ret i1 true
+;
+ %a = mul nsw i8 %x, 5
+ %b = icmp ne i8 %a, 130
+ ret i1 %b
+}
+
+define <2 x i1> @eq_nuw_rem_zero(<2 x i8> %x) {
+; CHECK-LABEL: @eq_nuw_rem_zero(
+; CHECK-NEXT: [[A:%.*]] = mul nuw <2 x i8> [[X:%.*]], <i8 5, i8 5>
+; CHECK-NEXT: [[B:%.*]] = icmp eq <2 x i8> [[A]], <i8 20, i8 20>
+; CHECK-NEXT: ret <2 x i1> [[B]]
+;
+ %a = mul nuw <2 x i8> %x, <i8 5, i8 5>
+ %b = icmp eq <2 x i8> %a, <i8 20, i8 20>
+ ret <2 x i1> %b
+}
+
+define <2 x i1> @eq_nuw_rem_zero_undef1(<2 x i8> %x) {
+; CHECK-LABEL: @eq_nuw_rem_zero_undef1(
+; CHECK-NEXT: [[A:%.*]] = mul nuw <2 x i8> [[X:%.*]], <i8 undef, i8 5>
+; CHECK-NEXT: [[B:%.*]] = icmp eq <2 x i8> [[A]], <i8 20, i8 20>
+; CHECK-NEXT: ret <2 x i1> [[B]]
+;
+ %a = mul nuw <2 x i8> %x, <i8 undef, i8 5>
+ %b = icmp eq <2 x i8> %a, <i8 20, i8 20>
+ ret <2 x i1> %b
+}
+
+define <2 x i1> @eq_nuw_rem_zero_undef2(<2 x i8> %x) {
+; CHECK-LABEL: @eq_nuw_rem_zero_undef2(
+; CHECK-NEXT: [[A:%.*]] = mul nuw <2 x i8> [[X:%.*]], <i8 5, i8 5>
+; CHECK-NEXT: [[B:%.*]] = icmp eq <2 x i8> [[A]], <i8 undef, i8 20>
+; CHECK-NEXT: ret <2 x i1> [[B]]
+;
+ %a = mul nuw <2 x i8> %x, <i8 5, i8 5>
+ %b = icmp eq <2 x i8> %a, <i8 undef, i8 20>
+ ret <2 x i1> %b
+}
+
+define i1 @ne_nuw_rem_zero(i8 %x) {
+; CHECK-LABEL: @ne_nuw_rem_zero(
; CHECK-NEXT: [[A:%.*]] = mul nuw i8 [[X:%.*]], 5
-; CHECK-NEXT: [[B:%.*]] = icmp ne i8 [[A]], 30
+; CHECK-NEXT: [[B:%.*]] = icmp ne i8 [[A]], -126
; CHECK-NEXT: ret i1 [[B]]
;
%a = mul nuw i8 %x, 5
- %b = icmp ne i8 %a, 30
+ %b = icmp ne i8 %a, 130
ret i1 %b
}
-define i1 @eq_rem_nz(i8 %x) {
-; CHECK-LABEL: @eq_rem_nz(
-; CHECK-NEXT: ret i1 false
+define i1 @ne_nuw_rem_zero_uses(i8 %x) {
+; CHECK-LABEL: @ne_nuw_rem_zero_uses(
+; CHECK-NEXT: [[A:%.*]] = mul nuw i8 [[X:%.*]], 5
+; CHECK-NEXT: call void @use(i8 [[A]])
+; CHECK-NEXT: [[B:%.*]] = icmp ne i8 [[A]], -126
+; CHECK-NEXT: ret i1 [[B]]
;
%a = mul nuw i8 %x, 5
- %b = icmp eq i8 %a, 31
+ call void @use(i8 %a)
+ %b = icmp ne i8 %a, 130
ret i1 %b
}
-define i1 @ne_rem_nz(i8 %x) {
-; CHECK-LABEL: @ne_rem_nz(
+; Impossible multiple should be handled by instsimplify.
+
+define i1 @eq_nuw_rem_nz(i8 %x) {
+; CHECK-LABEL: @eq_nuw_rem_nz(
+; CHECK-NEXT: ret i1 false
+;
+ %a = mul nuw i8 %x, -5
+ %b = icmp eq i8 %a, 20
+ ret i1 %b
+}
+
+; Impossible multiple should be handled by instsimplify.
+
+define i1 @ne_nuw_rem_nz(i8 %x) {
+; CHECK-LABEL: @ne_nuw_rem_nz(
; CHECK-NEXT: ret i1 true
;
%a = mul nuw i8 %x, 5
- %b = icmp ne i8 %a, 31
+ %b = icmp ne i8 %a, -30
ret i1 %b
}
More information about the llvm-commits
mailing list