1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
4 declare i64 @llvm.cttz.i64(i64, i1)
6 declare i64 @llvm.ctlz.i64(i64, i1)
8 declare <8 x i64> @llvm.cttz.v8i64(<8 x i64>, i1)
10 define i32 @test0(i64 %x) {
11 ; CHECK-LABEL: @test0(
13 ; CHECK-NEXT: [[C:%.*]] = icmp eq i64 [[X:%.*]], 0
14 ; CHECK-NEXT: br i1 [[C]], label [[EXIT:%.*]], label [[NON_ZERO:%.*]]
16 ; CHECK-NEXT: [[CTZ:%.*]] = call i64 @llvm.cttz.i64(i64 [[X]], i1 false), !range !0
17 ; CHECK-NEXT: [[CTZ32:%.*]] = trunc i64 [[CTZ]] to i32
18 ; CHECK-NEXT: br label [[EXIT]]
20 ; CHECK-NEXT: [[RES:%.*]] = phi i32 [ [[CTZ32]], [[NON_ZERO]] ], [ 0, [[START:%.*]] ]
21 ; CHECK-NEXT: ret i32 [[RES]]
24 %c = icmp eq i64 %x, 0
25 br i1 %c, label %exit, label %non_zero
28 %ctz = call i64 @llvm.cttz.i64(i64 %x, i1 false)
29 %ctz32 = trunc i64 %ctz to i32
33 %res = phi i32 [ %ctz32, %non_zero ], [ 0, %start ]
37 define i32 @test1(i64 %x) {
38 ; CHECK-LABEL: @test1(
40 ; CHECK-NEXT: [[C:%.*]] = icmp eq i64 [[X:%.*]], 0
41 ; CHECK-NEXT: br i1 [[C]], label [[EXIT:%.*]], label [[NON_ZERO:%.*]]
43 ; CHECK-NEXT: [[CTZ:%.*]] = call i64 @llvm.ctlz.i64(i64 [[X]], i1 false), !range !0
44 ; CHECK-NEXT: [[CTZ32:%.*]] = trunc i64 [[CTZ]] to i32
45 ; CHECK-NEXT: br label [[EXIT]]
47 ; CHECK-NEXT: [[RES:%.*]] = phi i32 [ [[CTZ32]], [[NON_ZERO]] ], [ 0, [[START:%.*]] ]
48 ; CHECK-NEXT: ret i32 [[RES]]
51 %c = icmp eq i64 %x, 0
52 br i1 %c, label %exit, label %non_zero
55 %ctz = call i64 @llvm.ctlz.i64(i64 %x, i1 false)
56 %ctz32 = trunc i64 %ctz to i32
60 %res = phi i32 [ %ctz32, %non_zero ], [ 0, %start ]
64 define <8 x i64> @test2(<8 x i64> %x) {
65 ; CHECK-LABEL: @test2(
67 ; CHECK-NEXT: [[A:%.*]] = icmp eq <8 x i64> [[X:%.*]], zeroinitializer
68 ; CHECK-NEXT: [[B:%.*]] = bitcast <8 x i1> [[A]] to i8
69 ; CHECK-NEXT: [[C:%.*]] = icmp eq i8 [[B]], 0
70 ; CHECK-NEXT: br i1 [[C]], label [[EXIT:%.*]], label [[NON_ZERO:%.*]]
72 ; CHECK-NEXT: [[CTZ:%.*]] = call <8 x i64> @llvm.cttz.v8i64(<8 x i64> [[X]], i1 false)
73 ; CHECK-NEXT: br label [[EXIT]]
75 ; CHECK-NEXT: [[RES:%.*]] = phi <8 x i64> [ [[CTZ]], [[NON_ZERO]] ], [ zeroinitializer, [[START:%.*]] ]
76 ; CHECK-NEXT: ret <8 x i64> [[RES]]
79 %a = icmp eq <8 x i64> %x, zeroinitializer
80 %b = bitcast <8 x i1> %a to i8
82 br i1 %c, label %exit, label %non_zero
85 ; NB: We cannot determine that vectors are known to be zero based
86 ; on the dominating condition
87 %ctz = call <8 x i64> @llvm.cttz.v8i64(<8 x i64> %x, i1 false)
91 %res = phi <8 x i64> [ %ctz, %non_zero ], [ zeroinitializer, %start ]