1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt %s -passes=instsimplify -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 = and i1 %smul.ov, %cmp
19 define i1 @t1_commutative(i4 %size, i4 %nmemb) {
20 ; CHECK-LABEL: @t1_commutative(
21 ; CHECK-NEXT: [[SMUL:%.*]] = tail call { i4, i1 } @llvm.smul.with.overflow.i4(i4 [[SIZE:%.*]], i4 [[NMEMB:%.*]])
22 ; CHECK-NEXT: [[SMUL_OV:%.*]] = extractvalue { i4, i1 } [[SMUL]], 1
23 ; CHECK-NEXT: ret i1 [[SMUL_OV]]
25 %cmp = icmp ne i4 %size, 0
26 %smul = tail call { i4, i1 } @llvm.smul.with.overflow.i4(i4 %size, i4 %nmemb)
27 %smul.ov = extractvalue { i4, i1 } %smul, 1
28 %and = and i1 %cmp, %smul.ov ; swapped
32 define i1 @n2_wrong_size(i4 %size0, i4 %size1, i4 %nmemb) {
33 ; CHECK-LABEL: @n2_wrong_size(
34 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i4 [[SIZE1:%.*]], 0
35 ; CHECK-NEXT: [[SMUL:%.*]] = tail call { i4, i1 } @llvm.smul.with.overflow.i4(i4 [[SIZE0:%.*]], i4 [[NMEMB:%.*]])
36 ; CHECK-NEXT: [[SMUL_OV:%.*]] = extractvalue { i4, i1 } [[SMUL]], 1
37 ; CHECK-NEXT: [[AND:%.*]] = and i1 [[SMUL_OV]], [[CMP]]
38 ; CHECK-NEXT: ret i1 [[AND]]
40 %cmp = icmp ne i4 %size1, 0 ; not %size0
41 %smul = tail call { i4, i1 } @llvm.smul.with.overflow.i4(i4 %size0, i4 %nmemb)
42 %smul.ov = extractvalue { i4, i1 } %smul, 1
43 %and = and i1 %smul.ov, %cmp
47 define i1 @n3_wrong_pred(i4 %size, i4 %nmemb) {
48 ; CHECK-LABEL: @n3_wrong_pred(
49 ; CHECK-NEXT: ret i1 false
51 %cmp = icmp eq i4 %size, 0 ; not 'ne'
52 %smul = tail call { i4, i1 } @llvm.smul.with.overflow.i4(i4 %size, i4 %nmemb)
53 %smul.ov = extractvalue { i4, i1 } %smul, 1
54 %and = and i1 %smul.ov, %cmp
58 define i1 @n4_not_and(i4 %size, i4 %nmemb) {
59 ; CHECK-LABEL: @n4_not_and(
60 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i4 [[SIZE:%.*]], 0
61 ; CHECK-NEXT: ret i1 [[CMP]]
63 %cmp = icmp ne i4 %size, 0
64 %smul = tail call { i4, i1 } @llvm.smul.with.overflow.i4(i4 %size, i4 %nmemb)
65 %smul.ov = extractvalue { i4, i1 } %smul, 1
66 %and = or i1 %smul.ov, %cmp ; not 'and'
70 define i1 @n5_not_zero(i4 %size, i4 %nmemb) {
71 ; CHECK-LABEL: @n5_not_zero(
72 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i4 [[SIZE:%.*]], 1
73 ; CHECK-NEXT: [[SMUL:%.*]] = tail call { i4, i1 } @llvm.smul.with.overflow.i4(i4 [[SIZE]], i4 [[NMEMB:%.*]])
74 ; CHECK-NEXT: [[SMUL_OV:%.*]] = extractvalue { i4, i1 } [[SMUL]], 1
75 ; CHECK-NEXT: [[AND:%.*]] = and i1 [[SMUL_OV]], [[CMP]]
76 ; CHECK-NEXT: ret i1 [[AND]]
78 %cmp = icmp ne i4 %size, 1 ; should be '0'
79 %smul = tail call { i4, i1 } @llvm.smul.with.overflow.i4(i4 %size, i4 %nmemb)
80 %smul.ov = extractvalue { i4, i1 } %smul, 1
81 %and = and i1 %smul.ov, %cmp