1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
4 declare i32 @llvm.smax.i32(i32 %a, i32 %b)
5 declare i32 @llvm.smin.i32(i32 %a, i32 %b)
6 declare i32 @llvm.umax.i32(i32 %a, i32 %b)
7 declare i32 @llvm.umin.i32(i32 %a, i32 %b)
9 define i32 @uadd_min_max(i32 %a, i32 %b) {
10 ; CHECK-LABEL: @uadd_min_max(
12 ; CHECK-NEXT: [[RES:%.*]] = add i32 [[A:%.*]], [[B:%.*]]
13 ; CHECK-NEXT: ret i32 [[RES]]
16 %max = call i32 @llvm.umax.i32(i32 %a, i32 %b)
17 %min = call i32 @llvm.umin.i32(i32 %a, i32 %b)
18 %res = add i32 %min, %max
22 define i32 @uadd_min_max_comm(i32 %a, i32 %b) {
23 ; CHECK-LABEL: @uadd_min_max_comm(
25 ; CHECK-NEXT: [[RES:%.*]] = add i32 [[B:%.*]], [[A:%.*]]
26 ; CHECK-NEXT: ret i32 [[RES]]
29 %max = call i32 @llvm.umax.i32(i32 %b, i32 %a)
30 %min = call i32 @llvm.umin.i32(i32 %a, i32 %b)
31 %res = add i32 %min, %max
35 define i32 @uadd_min_max_nuw_nsw(i32 %a, i32 %b) {
36 ; CHECK-LABEL: @uadd_min_max_nuw_nsw(
38 ; CHECK-NEXT: [[RES:%.*]] = add nuw nsw i32 [[A:%.*]], [[B:%.*]]
39 ; CHECK-NEXT: ret i32 [[RES]]
42 %max = call i32 @llvm.umax.i32(i32 %a, i32 %b)
43 %min = call i32 @llvm.umin.i32(i32 %a, i32 %b)
44 %res = add nuw nsw i32 %min, %max
48 define i32 @sadd_min_max(i32 %a, i32 %b) {
49 ; CHECK-LABEL: @sadd_min_max(
51 ; CHECK-NEXT: [[RES:%.*]] = add i32 [[A:%.*]], [[B:%.*]]
52 ; CHECK-NEXT: ret i32 [[RES]]
55 %max = call i32 @llvm.smax.i32(i32 %a, i32 %b)
56 %min = call i32 @llvm.smin.i32(i32 %a, i32 %b)
57 %res = add i32 %min, %max
61 define i32 @sadd_min_max_comm(i32 %a, i32 %b) {
62 ; CHECK-LABEL: @sadd_min_max_comm(
64 ; CHECK-NEXT: [[RES:%.*]] = add i32 [[B:%.*]], [[A:%.*]]
65 ; CHECK-NEXT: ret i32 [[RES]]
68 %max = call i32 @llvm.smax.i32(i32 %b, i32 %a)
69 %min = call i32 @llvm.smin.i32(i32 %a, i32 %b)
70 %res = add i32 %min, %max
74 define i32 @sadd_min_max_nuw_nsw(i32 %a, i32 %b) {
75 ; CHECK-LABEL: @sadd_min_max_nuw_nsw(
77 ; CHECK-NEXT: [[RES:%.*]] = add nuw nsw i32 [[A:%.*]], [[B:%.*]]
78 ; CHECK-NEXT: ret i32 [[RES]]
81 %max = call i32 @llvm.smax.i32(i32 %a, i32 %b)
82 %min = call i32 @llvm.smin.i32(i32 %a, i32 %b)
83 %res = add nuw nsw i32 %min, %max