1; RUN: opt -instcombine -S < %s | FileCheck %s
2
3; <rdar://problem/8606771>
4define i32 @main(i32 %argc) {
5; CHECK-LABEL: @main(
6; CHECK-NEXT:    [[TMP3151:%.*]] = trunc i32 %argc to i8
7; CHECK-NEXT:    [[TMP1:%.*]] = shl i8 [[TMP3151]], 5
8; CHECK-NEXT:    [[TMP4126:%.*]] = and i8 [[TMP1]], 64
9; CHECK-NEXT:    [[TMP4127:%.*]] = xor i8 [[TMP4126]], 64
10; CHECK-NEXT:    [[TMP4086:%.*]] = zext i8 [[TMP4127]] to i32
11; CHECK-NEXT:    ret i32 [[TMP4086]]
12;
13  %tmp3151 = trunc i32 %argc to i8
14  %tmp3161 = or i8 %tmp3151, -17
15  %tmp3162 = and i8 %tmp3151, 122
16  %tmp3163 = xor i8 %tmp3162, -17
17  %tmp4114 = shl i8 %tmp3163, 6
18  %tmp4115 = xor i8 %tmp4114, %tmp3163
19  %tmp4120 = xor i8 %tmp3161, %tmp4115
20  %tmp4126 = lshr i8 %tmp4120, 7
21  %tmp4127 = mul i8 %tmp4126, 64
22  %tmp4086 = zext i8 %tmp4127 to i32
23  ret i32 %tmp4086
24}
25
26; rdar://8739316
27define i8 @foo(i8 %arg, i8 %arg1) {
28; CHECK-LABEL: @foo(
29; CHECK-NEXT:    [[TMP:%.*]] = shl i8 %arg, 7
30; CHECK-NEXT:    [[TMP2:%.*]] = and i8 %arg1, 84
31; CHECK-NEXT:    [[TMP3:%.*]] = and i8 %arg1, -118
32; CHECK-NEXT:    [[TMP4:%.*]] = and i8 %arg1, 33
33; CHECK-NEXT:    [[TMP5:%.*]] = sub nsw i8 40, [[TMP2]]
34; CHECK-NEXT:    [[TMP6:%.*]] = and i8 [[TMP5]], 84
35; CHECK-NEXT:    [[TMP7:%.*]] = or i8 [[TMP4]], [[TMP6]]
36; CHECK-NEXT:    [[TMP8:%.*]] = xor i8 [[TMP]], [[TMP3]]
37; CHECK-NEXT:    [[TMP9:%.*]] = or i8 [[TMP7]], [[TMP8]]
38; CHECK-NEXT:    [[TMP10:%.*]] = lshr i8 [[TMP8]], 7
39; CHECK-NEXT:    [[TMP11:%.*]] = shl nuw nsw i8 [[TMP10]], 5
40; CHECK-NEXT:    [[TMP12:%.*]] = xor i8 [[TMP11]], [[TMP9]]
41; CHECK-NEXT:    ret i8 [[TMP12]]
42;
43  %tmp = shl i8 %arg, 7
44  %tmp2 = and i8 %arg1, 84
45  %tmp3 = and i8 %arg1, -118
46  %tmp4 = and i8 %arg1, 33
47  %tmp5 = sub i8 -88, %tmp2
48  %tmp6 = and i8 %tmp5, 84
49  %tmp7 = or i8 %tmp4, %tmp6
50  %tmp8 = xor i8 %tmp, %tmp3
51  %tmp9 = or i8 %tmp7, %tmp8
52  %tmp10 = lshr i8 %tmp8, 7
53  %tmp11 = shl i8 %tmp10, 5
54  %tmp12 = xor i8 %tmp11, %tmp9
55  ret i8 %tmp12
56}
57
58