1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -aggressive-instcombine -S | FileCheck %s
4 define void @trunc_one_add(i16* %a, i8 %b) {
5 ; CHECK-LABEL: @trunc_one_add(
6 ; CHECK-NEXT: [[ZEXT:%.*]] = zext i8 [[B:%.*]] to i16
7 ; CHECK-NEXT: [[SHR:%.*]] = lshr i16 [[ZEXT]], 1
8 ; CHECK-NEXT: [[ADD:%.*]] = add i16 [[ZEXT]], [[SHR]]
9 ; CHECK-NEXT: store i16 [[ADD]], i16* [[A:%.*]], align 2
10 ; CHECK-NEXT: ret void
12 %zext = zext i8 %b to i32
13 %shr = lshr i32 %zext, 1
14 %add = add nsw i32 %zext, %shr
15 %trunc = trunc i32 %add to i16
16 store i16 %trunc, i16* %a, align 2
20 define void @trunc_two_adds(i16* %a, i8 %b, i8 %c) {
21 ; CHECK-LABEL: @trunc_two_adds(
22 ; CHECK-NEXT: [[ZEXT1:%.*]] = zext i8 [[B:%.*]] to i16
23 ; CHECK-NEXT: [[ZEXT2:%.*]] = zext i8 [[C:%.*]] to i16
24 ; CHECK-NEXT: [[ADD1:%.*]] = add i16 [[ZEXT1]], [[ZEXT2]]
25 ; CHECK-NEXT: [[SHR1:%.*]] = lshr i16 [[ADD1]], 1
26 ; CHECK-NEXT: [[ADD2:%.*]] = add i16 [[ADD1]], [[SHR1]]
27 ; CHECK-NEXT: [[SHR2:%.*]] = lshr i16 [[ADD2]], 2
28 ; CHECK-NEXT: store i16 [[SHR2]], i16* [[A:%.*]], align 2
29 ; CHECK-NEXT: ret void
31 %zext1 = zext i8 %b to i32
32 %zext2 = zext i8 %c to i32
33 %add1 = add nuw nsw i32 %zext1, %zext2
34 %shr1 = lshr i32 %add1, 1
35 %add2 = add nuw nsw i32 %add1, %shr1
36 %shr2 = lshr i32 %add2, 2
37 %trunc = trunc i32 %shr2 to i16
38 store i16 %trunc, i16* %a, align 2