[NFC] Add baseline tests for int isKnownNonZero

Add baseline tests for improvements of isKnownNonZero for integer types.

Differential Revision: https://reviews.llvm.org/D60932

llvm-svn: 359267
This commit is contained in:
Dan Robertson 2019-04-26 02:55:54 +00:00
parent 59d0500bd0
commit 9e441aee50
2 changed files with 197 additions and 0 deletions

View File

@ -0,0 +1,93 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -instcombine -S | FileCheck %s
declare i64 @llvm.cttz.i64(i64, i1)
declare i64 @llvm.ctlz.i64(i64, i1)
declare <8 x i64> @llvm.cttz.v8i64(<8 x i64>, i1)
define i32 @test0(i64 %x) {
; CHECK-LABEL: @test0(
; CHECK-NEXT: start:
; CHECK-NEXT: [[C:%.*]] = icmp eq i64 [[X:%.*]], 0
; CHECK-NEXT: br i1 [[C]], label [[EXIT:%.*]], label [[NON_ZERO:%.*]]
; CHECK: non_zero:
; CHECK-NEXT: [[CTZ:%.*]] = call i64 @llvm.cttz.i64(i64 [[X]], i1 false), !range !0
; CHECK-NEXT: [[CTZ32:%.*]] = trunc i64 [[CTZ]] to i32
; CHECK-NEXT: br label [[EXIT]]
; CHECK: exit:
; CHECK-NEXT: [[RES:%.*]] = phi i32 [ [[CTZ32]], [[NON_ZERO]] ], [ 0, [[START:%.*]] ]
; CHECK-NEXT: ret i32 [[RES]]
;
start:
%c = icmp eq i64 %x, 0
br i1 %c, label %exit, label %non_zero
non_zero:
%ctz = call i64 @llvm.cttz.i64(i64 %x, i1 false)
%ctz32 = trunc i64 %ctz to i32
br label %exit
exit:
%res = phi i32 [ %ctz32, %non_zero ], [ 0, %start ]
ret i32 %res
}
define i32 @test1(i64 %x) {
; CHECK-LABEL: @test1(
; CHECK-NEXT: start:
; CHECK-NEXT: [[C:%.*]] = icmp eq i64 [[X:%.*]], 0
; CHECK-NEXT: br i1 [[C]], label [[EXIT:%.*]], label [[NON_ZERO:%.*]]
; CHECK: non_zero:
; CHECK-NEXT: [[CTZ:%.*]] = call i64 @llvm.ctlz.i64(i64 [[X]], i1 false), !range !0
; CHECK-NEXT: [[CTZ32:%.*]] = trunc i64 [[CTZ]] to i32
; CHECK-NEXT: br label [[EXIT]]
; CHECK: exit:
; CHECK-NEXT: [[RES:%.*]] = phi i32 [ [[CTZ32]], [[NON_ZERO]] ], [ 0, [[START:%.*]] ]
; CHECK-NEXT: ret i32 [[RES]]
;
start:
%c = icmp eq i64 %x, 0
br i1 %c, label %exit, label %non_zero
non_zero:
%ctz = call i64 @llvm.ctlz.i64(i64 %x, i1 false)
%ctz32 = trunc i64 %ctz to i32
br label %exit
exit:
%res = phi i32 [ %ctz32, %non_zero ], [ 0, %start ]
ret i32 %res
}
define <8 x i64> @test2(<8 x i64> %x) {
; CHECK-LABEL: @test2(
; CHECK-NEXT: start:
; CHECK-NEXT: [[A:%.*]] = icmp eq <8 x i64> [[X:%.*]], zeroinitializer
; CHECK-NEXT: [[B:%.*]] = bitcast <8 x i1> [[A]] to i8
; CHECK-NEXT: [[C:%.*]] = icmp eq i8 [[B]], 0
; CHECK-NEXT: br i1 [[C]], label [[EXIT:%.*]], label [[NON_ZERO:%.*]]
; CHECK: non_zero:
; CHECK-NEXT: [[CTZ:%.*]] = call <8 x i64> @llvm.cttz.v8i64(<8 x i64> [[X]], i1 false)
; CHECK-NEXT: br label [[EXIT]]
; CHECK: exit:
; CHECK-NEXT: [[RES:%.*]] = phi <8 x i64> [ [[CTZ]], [[NON_ZERO]] ], [ zeroinitializer, [[START:%.*]] ]
; CHECK-NEXT: ret <8 x i64> [[RES]]
;
start:
%a = icmp eq <8 x i64> %x, zeroinitializer
%b = bitcast <8 x i1> %a to i8
%c = icmp eq i8 %b, 0
br i1 %c, label %exit, label %non_zero
non_zero:
; NB: We cannot determine that vectors are known to be zero based
; on the dominating condition
%ctz = call <8 x i64> @llvm.cttz.v8i64(<8 x i64> %x, i1 false)
br label %exit
exit:
%res = phi <8 x i64> [ %ctz, %non_zero ], [ zeroinitializer, %start ]
ret <8 x i64> %res
}

View File

@ -0,0 +1,104 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -instsimplify -S | FileCheck %s
define i64 @test0(i64 %x) {
; CHECK-LABEL: @test0(
; CHECK-NEXT: start:
; CHECK-NEXT: [[A:%.*]] = icmp eq i64 [[X:%.*]], 0
; CHECK-NEXT: br i1 [[A]], label [[EXIT:%.*]], label [[NON_ZERO:%.*]]
; CHECK: non_zero:
; CHECK-NEXT: [[B:%.*]] = icmp eq i64 [[X]], 0
; CHECK-NEXT: br i1 [[B]], label [[UNREACHABLE:%.*]], label [[EXIT]]
; CHECK: unreachable:
; CHECK-NEXT: br label [[EXIT]]
; CHECK: exit:
; CHECK-NEXT: [[C:%.*]] = phi i64 [ 0, [[START:%.*]] ], [ 1, [[NON_ZERO]] ], [ 2, [[UNREACHABLE]] ]
; CHECK-NEXT: ret i64 [[C]]
;
start:
%a = icmp eq i64 %x, 0
br i1 %a, label %exit, label %non_zero
non_zero:
%b = icmp eq i64 %x, 0
br i1 %b, label %unreachable, label %exit
unreachable:
br label %exit
exit:
%c = phi i64 [ 0, %start ], [ 1, %non_zero ], [ 2, %unreachable ]
ret i64 %c
}
define i64 @test1(i64 %x) {
; CHECK-LABEL: @test1(
; CHECK-NEXT: start:
; CHECK-NEXT: [[A:%.*]] = icmp eq i64 [[X:%.*]], 0
; CHECK-NEXT: br i1 [[A]], label [[EXIT:%.*]], label [[NON_ZERO:%.*]]
; CHECK: non_zero:
; CHECK-NEXT: [[B:%.*]] = icmp ugt i64 [[X]], 0
; CHECK-NEXT: br i1 [[B]], label [[EXIT]], label [[UNREACHABLE:%.*]]
; CHECK: unreachable:
; CHECK-NEXT: br label [[EXIT]]
; CHECK: exit:
; CHECK-NEXT: [[C:%.*]] = phi i64 [ 0, [[START:%.*]] ], [ [[X]], [[NON_ZERO]] ], [ 0, [[UNREACHABLE]] ]
; CHECK-NEXT: ret i64 [[C]]
;
start:
%a = icmp eq i64 %x, 0
br i1 %a, label %exit, label %non_zero
non_zero:
%b = icmp ugt i64 %x, 0
br i1 %b, label %exit, label %unreachable
unreachable:
br label %exit
exit:
%c = phi i64 [ 0, %start ], [ %x, %non_zero ], [ 0, %unreachable ]
ret i64 %c
}
define i1 @test2(i64 %x, i1 %y) {
; CHECK-LABEL: @test2(
; CHECK-NEXT: start:
; CHECK-NEXT: [[A:%.*]] = icmp eq i64 [[X:%.*]], 0
; CHECK-NEXT: br i1 [[A]], label [[EXIT:%.*]], label [[NON_ZERO:%.*]]
; CHECK: non_zero:
; CHECK-NEXT: br i1 [[Y:%.*]], label [[ONE:%.*]], label [[TWO:%.*]]
; CHECK: one:
; CHECK-NEXT: br label [[MAINBLOCK:%.*]]
; CHECK: two:
; CHECK-NEXT: br label [[MAINBLOCK]]
; CHECK: mainblock:
; CHECK-NEXT: [[P:%.*]] = phi i64 [ [[X]], [[ONE]] ], [ 42, [[TWO]] ]
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[P]], 0
; CHECK-NEXT: br label [[EXIT]]
; CHECK: exit:
; CHECK-NEXT: [[RES:%.*]] = phi i1 [ [[CMP]], [[MAINBLOCK]] ], [ true, [[START:%.*]] ]
; CHECK-NEXT: ret i1 [[RES]]
;
start:
%a = icmp eq i64 %x, 0
br i1 %a, label %exit, label %non_zero
non_zero:
br i1 %y, label %one, label %two
one:
br label %mainblock
two:
br label %mainblock
mainblock:
%p = phi i64 [ %x, %one ], [ 42, %two ]
%cmp = icmp eq i64 %p, 0
br label %exit
exit:
%res = phi i1 [ %cmp, %mainblock ], [ 1, %start ]
ret i1 %res
}