1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
4 declare void @use.i8(i8)
5 define i8 @fold_add_zext_eq_0(i8 %x) {
6 ; CHECK-LABEL: @fold_add_zext_eq_0(
7 ; CHECK-NEXT: [[R:%.*]] = call i8 @llvm.umax.i8(i8 [[X:%.*]], i8 1)
8 ; CHECK-NEXT: ret i8 [[R]]
10 %x_eq = icmp eq i8 %x, 0
11 %x_eq_ext = zext i1 %x_eq to i8
12 %r = add i8 %x, %x_eq_ext
16 define <2 x i8> @fold_add_sext_eq_4_6(<2 x i6> %xx) {
17 ; CHECK-LABEL: @fold_add_sext_eq_4_6(
18 ; CHECK-NEXT: [[X:%.*]] = zext <2 x i6> [[XX:%.*]] to <2 x i8>
19 ; CHECK-NEXT: [[X_EQ:%.*]] = icmp eq <2 x i8> [[X]], <i8 4, i8 -127>
20 ; CHECK-NEXT: [[R:%.*]] = select <2 x i1> [[X_EQ]], <2 x i8> <i8 3, i8 -128>, <2 x i8> [[X]]
21 ; CHECK-NEXT: ret <2 x i8> [[R]]
23 %x = zext <2 x i6> %xx to <2 x i8>
24 %x_eq = icmp eq <2 x i8> %x, <i8 4, i8 129>
25 %x_eq_ext = sext <2 x i1> %x_eq to <2 x i8>
26 %r = add <2 x i8> %x_eq_ext, %x
30 define i8 @fold_add_zext_eq_0_fail_multiuse_exp(i8 %x) {
31 ; CHECK-LABEL: @fold_add_zext_eq_0_fail_multiuse_exp(
32 ; CHECK-NEXT: [[X_EQ:%.*]] = icmp eq i8 [[X:%.*]], 0
33 ; CHECK-NEXT: [[X_EQ_EXT:%.*]] = zext i1 [[X_EQ]] to i8
34 ; CHECK-NEXT: [[R:%.*]] = add i8 [[X]], [[X_EQ_EXT]]
35 ; CHECK-NEXT: call void @use.i8(i8 [[X_EQ_EXT]])
36 ; CHECK-NEXT: ret i8 [[R]]
38 %x_eq = icmp eq i8 %x, 0
39 %x_eq_ext = zext i1 %x_eq to i8
40 %r = add i8 %x, %x_eq_ext
41 call void @use.i8(i8 %x_eq_ext)
45 define i8 @fold_add_sext_eq_4_fail_wrong_cond(i8 %x, i8 %y) {
46 ; CHECK-LABEL: @fold_add_sext_eq_4_fail_wrong_cond(
47 ; CHECK-NEXT: [[X_EQ:%.*]] = icmp eq i8 [[Y:%.*]], 4
48 ; CHECK-NEXT: [[X_EQ_EXT:%.*]] = sext i1 [[X_EQ]] to i8
49 ; CHECK-NEXT: [[R:%.*]] = add i8 [[X:%.*]], [[X_EQ_EXT]]
50 ; CHECK-NEXT: call void @use.i8(i8 [[X_EQ_EXT]])
51 ; CHECK-NEXT: ret i8 [[R]]
53 %x_eq = icmp eq i8 %y, 4
54 %x_eq_ext = sext i1 %x_eq to i8
55 %r = add i8 %x, %x_eq_ext
56 call void @use.i8(i8 %x_eq_ext)