1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt %s -passes=instcombine -S | FileCheck %s
4 declare { i4, i1 } @llvm.smul.with.overflow.i4(i4, i4) #1
6 define i1 @t0_smul(i4 %size, i4 %nmemb) {
7 ; CHECK-LABEL: @t0_smul(
8 ; CHECK-NEXT: [[SMUL:%.*]] = tail call { i4, i1 } @llvm.smul.with.overflow.i4(i4 [[SIZE:%.*]], i4 [[NMEMB:%.*]])
9 ; CHECK-NEXT: [[SMUL_OV:%.*]] = extractvalue { i4, i1 } [[SMUL]], 1
10 ; CHECK-NEXT: ret i1 [[SMUL_OV]]
12 %cmp = icmp ne i4 %size, 0
13 %smul = tail call { i4, i1 } @llvm.smul.with.overflow.i4(i4 %size, i4 %nmemb)
14 %smul.ov = extractvalue { i4, i1 } %smul, 1
15 %and = select i1 %smul.ov, i1 %cmp, i1 false
19 define i1 @t1_commutative(i4 %size, i4 %nmemb) {
20 ; CHECK-LABEL: @t1_commutative(
21 ; CHECK-NEXT: [[NMEMB_FR:%.*]] = freeze i4 [[NMEMB:%.*]]
22 ; CHECK-NEXT: [[SMUL:%.*]] = tail call { i4, i1 } @llvm.smul.with.overflow.i4(i4 [[SIZE:%.*]], i4 [[NMEMB_FR]])
23 ; CHECK-NEXT: [[SMUL_OV:%.*]] = extractvalue { i4, i1 } [[SMUL]], 1
24 ; CHECK-NEXT: ret i1 [[SMUL_OV]]
26 %cmp = icmp ne i4 %size, 0
27 %smul = tail call { i4, i1 } @llvm.smul.with.overflow.i4(i4 %size, i4 %nmemb)
28 %smul.ov = extractvalue { i4, i1 } %smul, 1
29 %and = select i1 %cmp, i1 %smul.ov, i1 false ; swapped
33 define i1 @n2_wrong_size(i4 %size0, i4 %size1, i4 %nmemb) {
34 ; CHECK-LABEL: @n2_wrong_size(
35 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i4 [[SIZE1:%.*]], 0
36 ; CHECK-NEXT: [[SMUL:%.*]] = tail call { i4, i1 } @llvm.smul.with.overflow.i4(i4 [[SIZE0:%.*]], i4 [[NMEMB:%.*]])
37 ; CHECK-NEXT: [[SMUL_OV:%.*]] = extractvalue { i4, i1 } [[SMUL]], 1
38 ; CHECK-NEXT: [[AND:%.*]] = select i1 [[SMUL_OV]], i1 [[CMP]], i1 false
39 ; CHECK-NEXT: ret i1 [[AND]]
41 %cmp = icmp ne i4 %size1, 0 ; not %size0
42 %smul = tail call { i4, i1 } @llvm.smul.with.overflow.i4(i4 %size0, i4 %nmemb)
43 %smul.ov = extractvalue { i4, i1 } %smul, 1
44 %and = select i1 %smul.ov, i1 %cmp, i1 false
48 define i1 @n3_wrong_pred(i4 %size, i4 %nmemb) {
49 ; CHECK-LABEL: @n3_wrong_pred(
50 ; CHECK-NEXT: ret i1 false
52 %cmp = icmp eq i4 %size, 0 ; not 'ne'
53 %smul = tail call { i4, i1 } @llvm.smul.with.overflow.i4(i4 %size, i4 %nmemb)
54 %smul.ov = extractvalue { i4, i1 } %smul, 1
55 %and = select i1 %smul.ov, i1 %cmp, i1 false
59 define i1 @n4_not_and(i4 %size, i4 %nmemb) {
60 ; CHECK-LABEL: @n4_not_and(
61 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i4 [[SIZE:%.*]], 0
62 ; CHECK-NEXT: ret i1 [[CMP]]
64 %cmp = icmp ne i4 %size, 0
65 %smul = tail call { i4, i1 } @llvm.smul.with.overflow.i4(i4 %size, i4 %nmemb)
66 %smul.ov = extractvalue { i4, i1 } %smul, 1
67 %and = select i1 %smul.ov, i1 true, i1 %cmp ; not 'and'
71 define i1 @n5_not_zero(i4 %size, i4 %nmemb) {
72 ; CHECK-LABEL: @n5_not_zero(
73 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i4 [[SIZE:%.*]], 1
74 ; CHECK-NEXT: [[SMUL:%.*]] = tail call { i4, i1 } @llvm.smul.with.overflow.i4(i4 [[SIZE]], i4 [[NMEMB:%.*]])
75 ; CHECK-NEXT: [[SMUL_OV:%.*]] = extractvalue { i4, i1 } [[SMUL]], 1
76 ; CHECK-NEXT: [[AND:%.*]] = and i1 [[SMUL_OV]], [[CMP]]
77 ; CHECK-NEXT: ret i1 [[AND]]
79 %cmp = icmp ne i4 %size, 1 ; should be '0'
80 %smul = tail call { i4, i1 } @llvm.smul.with.overflow.i4(i4 %size, i4 %nmemb)
81 %smul.ov = extractvalue { i4, i1 } %smul, 1
82 %and = select i1 %smul.ov, i1 %cmp, i1 false