1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt %s -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: [[CMP:%.*]] = icmp eq i4 [[SIZE:%.*]], 0
50 ; CHECK-NEXT: [[SMUL:%.*]] = tail call { i4, i1 } @llvm.smul.with.overflow.i4(i4 [[SIZE]], i4 [[NMEMB:%.*]])
51 ; CHECK-NEXT: [[SMUL_OV:%.*]] = extractvalue { i4, i1 } [[SMUL]], 1
52 ; CHECK-NEXT: [[AND:%.*]] = and i1 [[SMUL_OV]], [[CMP]]
53 ; CHECK-NEXT: ret i1 [[AND]]
55 %cmp = icmp eq i4 %size, 0 ; not 'ne'
56 %smul = tail call { i4, i1 } @llvm.smul.with.overflow.i4(i4 %size, i4 %nmemb)
57 %smul.ov = extractvalue { i4, i1 } %smul, 1
58 %and = and i1 %smul.ov, %cmp
62 define i1 @n4_not_and(i4 %size, i4 %nmemb) {
63 ; CHECK-LABEL: @n4_not_and(
64 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i4 [[SIZE:%.*]], 0
65 ; CHECK-NEXT: [[SMUL:%.*]] = tail call { i4, i1 } @llvm.smul.with.overflow.i4(i4 [[SIZE]], i4 [[NMEMB:%.*]])
66 ; CHECK-NEXT: [[SMUL_OV:%.*]] = extractvalue { i4, i1 } [[SMUL]], 1
67 ; CHECK-NEXT: [[AND:%.*]] = or i1 [[SMUL_OV]], [[CMP]]
68 ; CHECK-NEXT: ret i1 [[AND]]
70 %cmp = icmp ne i4 %size, 0
71 %smul = tail call { i4, i1 } @llvm.smul.with.overflow.i4(i4 %size, i4 %nmemb)
72 %smul.ov = extractvalue { i4, i1 } %smul, 1
73 %and = or i1 %smul.ov, %cmp ; not 'and'
77 define i1 @n5_not_zero(i4 %size, i4 %nmemb) {
78 ; CHECK-LABEL: @n5_not_zero(
79 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i4 [[SIZE:%.*]], 1
80 ; CHECK-NEXT: [[SMUL:%.*]] = tail call { i4, i1 } @llvm.smul.with.overflow.i4(i4 [[SIZE]], i4 [[NMEMB:%.*]])
81 ; CHECK-NEXT: [[SMUL_OV:%.*]] = extractvalue { i4, i1 } [[SMUL]], 1
82 ; CHECK-NEXT: [[AND:%.*]] = and i1 [[SMUL_OV]], [[CMP]]
83 ; CHECK-NEXT: ret i1 [[AND]]
85 %cmp = icmp ne i4 %size, 1 ; should be '0'
86 %smul = tail call { i4, i1 } @llvm.smul.with.overflow.i4(i4 %size, i4 %nmemb)
87 %smul.ov = extractvalue { i4, i1 } %smul, 1
88 %and = and i1 %smul.ov, %cmp