1 ; RUN: opt < %s -instcombine -S | FileCheck %s
3 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
5 declare i32 @llvm.ctpop.i32(i32)
6 declare i32 @llvm.ctlz.i32(i32)
7 declare i32 @llvm.cttz.i32(i32)
9 define i64 @test1(i32 %x) {
10 %t = call i32 @llvm.ctpop.i32(i32 %x)
11 %s = sext i32 %t to i64
18 define i64 @test2(i32 %x) {
19 %t = call i32 @llvm.ctlz.i32(i32 %x)
20 %s = sext i32 %t to i64
27 define i64 @test3(i32 %x) {
28 %t = call i32 @llvm.cttz.i32(i32 %x)
29 %s = sext i32 %t to i64
36 define i64 @test4(i32 %x) {
38 %s = sext i32 %t to i64
45 define i64 @test5(i32 %x) {
46 %t = urem i32 %x, 30000
47 %s = sext i32 %t to i64
53 define i64 @test6(i32 %x) {
56 %s = sext i32 %t to i64
62 define i64 @test7(i32 %x) {
64 %u = sub i32 20000, %t
65 %s = sext i32 %u to i64
68 ; CHECK: zext i32 %u to i64
71 define i32 @test8(i8 %a, i32 %f, i1 %p, i32* %z) {
73 %e = select i1 %p, i32 %d, i32 0
74 %s = trunc i32 %e to i16
75 %n = sext i16 %s to i32
78 ; CHECK: %d = lshr i32 %f, 24
79 ; CHECK: %n = select i1 %p, i32 %d, i32 0
84 define i16 @test9(i16 %t, i1 %cond) nounwind {
86 br i1 %cond, label %T, label %F
88 %t2 = sext i16 %t to i32
92 %V = phi i32 [%t2, %T], [42, %entry]
93 %W = trunc i32 %V to i16
97 ; CHECK-NEXT: br label %F
100 ; CHECK-NEXT: ret i16
104 define i32 @test10(i32 %i) nounwind {
106 %tmp12 = trunc i32 %i to i8
107 %tmp16 = shl i8 %tmp12, 6
108 %a = ashr i8 %tmp16, 6
109 %b = sext i8 %a to i32
112 ; CHECK: shl i32 %i, 30
113 ; CHECK-NEXT: ashr i32
114 ; CHECK-NEXT: ret i32
117 define void @test11(<2 x i16> %srcA, <2 x i16> %srcB, <2 x i16>* %dst) {
118 %cmp = icmp eq <2 x i16> %srcB, %srcA
119 %sext = sext <2 x i1> %cmp to <2 x i16>
120 %tmask = ashr <2 x i16> %sext, <i16 15, i16 15>
121 store <2 x i16> %tmask, <2 x i16>* %dst
124 ; CHECK-NEXT: icmp eq
125 ; CHECK-NEXT: sext <2 x i1>
126 ; CHECK-NEXT: store <2 x i16>