1; RUN: opt < %s -instcombine -S | FileCheck %s 2 3declare i16 @llvm.bswap.i16(i16) 4declare i32 @llvm.bswap.i32(i32) 5declare <2 x i64> @llvm.bswap.v2i64(<2 x i64>) 6declare i33 @llvm.cttz.i33(i33, i1) 7declare i32 @llvm.ctlz.i32(i32, i1) 8declare i8 @llvm.ctpop.i8(i8) 9declare i11 @llvm.ctpop.i11(i11) 10declare <2 x i32> @llvm.cttz.v2i32(<2 x i32>, i1) 11declare <2 x i32> @llvm.ctlz.v2i32(<2 x i32>, i1) 12declare <2 x i32> @llvm.ctpop.v2i32(<2 x i32>) 13 14define i1 @bswap_eq_i16(i16 %x) { 15; CHECK-LABEL: @bswap_eq_i16( 16; CHECK-NEXT: [[CMP:%.*]] = icmp eq i16 %x, 256 17; CHECK-NEXT: ret i1 [[CMP]] 18; 19 %bs = call i16 @llvm.bswap.i16(i16 %x) 20 %cmp = icmp eq i16 %bs, 1 21 ret i1 %cmp 22} 23 24define i1 @bswap_ne_i32(i32 %x) { 25; CHECK-LABEL: @bswap_ne_i32( 26; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 %x, 33554432 27; CHECK-NEXT: ret i1 [[CMP]] 28; 29 %bs = tail call i32 @llvm.bswap.i32(i32 %x) 30 %cmp = icmp ne i32 %bs, 2 31 ret i1 %cmp 32} 33 34define <2 x i1> @bswap_eq_v2i64(<2 x i64> %x) { 35; CHECK-LABEL: @bswap_eq_v2i64( 36; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i64> %x, <i64 216172782113783808, i64 216172782113783808> 37; CHECK-NEXT: ret <2 x i1> [[CMP]] 38; 39 %bs = tail call <2 x i64> @llvm.bswap.v2i64(<2 x i64> %x) 40 %cmp = icmp eq <2 x i64> %bs, <i64 3, i64 3> 41 ret <2 x i1> %cmp 42} 43 44define i1 @ctlz_eq_bitwidth_i32(i32 %x) { 45; CHECK-LABEL: @ctlz_eq_bitwidth_i32( 46; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 %x, 0 47; CHECK-NEXT: ret i1 [[CMP]] 48; 49 %lz = tail call i32 @llvm.ctlz.i32(i32 %x, i1 false) 50 %cmp = icmp eq i32 %lz, 32 51 ret i1 %cmp 52} 53 54define <2 x i1> @ctlz_ne_bitwidth_v2i32(<2 x i32> %a) { 55; CHECK-LABEL: @ctlz_ne_bitwidth_v2i32( 56; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i32> %a, zeroinitializer 57; CHECK-NEXT: ret <2 x i1> [[CMP]] 58; 59 %x = tail call <2 x i32> @llvm.ctlz.v2i32(<2 x i32> %a, i1 false) 60 %cmp = icmp ne <2 x i32> %x, <i32 32, i32 32> 61 ret <2 x i1> %cmp 62} 63 64define i1 @cttz_ne_bitwidth_i33(i33 %x) { 65; CHECK-LABEL: @cttz_ne_bitwidth_i33( 66; CHECK-NEXT: [[CMP:%.*]] = icmp ne i33 %x, 0 67; CHECK-NEXT: ret i1 [[CMP]] 68; 69 %tz = tail call i33 @llvm.cttz.i33(i33 %x, i1 false) 70 %cmp = icmp ne i33 %tz, 33 71 ret i1 %cmp 72} 73 74define <2 x i1> @cttz_eq_bitwidth_v2i32(<2 x i32> %a) { 75; CHECK-LABEL: @cttz_eq_bitwidth_v2i32( 76; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i32> %a, zeroinitializer 77; CHECK-NEXT: ret <2 x i1> [[CMP]] 78; 79 %x = tail call <2 x i32> @llvm.cttz.v2i32(<2 x i32> %a, i1 false) 80 %cmp = icmp eq <2 x i32> %x, <i32 32, i32 32> 81 ret <2 x i1> %cmp 82} 83 84define i1 @ctpop_eq_zero_i11(i11 %x) { 85; CHECK-LABEL: @ctpop_eq_zero_i11( 86; CHECK-NEXT: [[CMP:%.*]] = icmp eq i11 %x, 0 87; CHECK-NEXT: ret i1 [[CMP]] 88; 89 %pop = tail call i11 @llvm.ctpop.i11(i11 %x) 90 %cmp = icmp eq i11 %pop, 0 91 ret i1 %cmp 92} 93 94define <2 x i1> @ctpop_ne_zero_v2i32(<2 x i32> %x) { 95; CHECK-LABEL: @ctpop_ne_zero_v2i32( 96; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i32> %x, zeroinitializer 97; CHECK-NEXT: ret <2 x i1> [[CMP]] 98; 99 %pop = tail call <2 x i32> @llvm.ctpop.v2i32(<2 x i32> %x) 100 %cmp = icmp ne <2 x i32> %pop, zeroinitializer 101 ret <2 x i1> %cmp 102} 103 104define i1 @ctpop_eq_bitwidth_i8(i8 %x) { 105; CHECK-LABEL: @ctpop_eq_bitwidth_i8( 106; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 %x, -1 107; CHECK-NEXT: ret i1 [[CMP]] 108; 109 %pop = tail call i8 @llvm.ctpop.i8(i8 %x) 110 %cmp = icmp eq i8 %pop, 8 111 ret i1 %cmp 112} 113 114define <2 x i1> @ctpop_ne_bitwidth_v2i32(<2 x i32> %x) { 115; CHECK-LABEL: @ctpop_ne_bitwidth_v2i32( 116; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i32> %x, <i32 -1, i32 -1> 117; CHECK-NEXT: ret <2 x i1> [[CMP]] 118; 119 %pop = tail call <2 x i32> @llvm.ctpop.v2i32(<2 x i32> %x) 120 %cmp = icmp ne <2 x i32> %pop, <i32 32, i32 32> 121 ret <2 x i1> %cmp 122} 123 124