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_umul(i4 %size, i4 %nmemb) {
7 ; CHECK-LABEL: @t0_umul(
8 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i4 [[SIZE:%.*]], 0
9 ; CHECK-NEXT: [[SMUL:%.*]] = tail call { i4, i1 } @llvm.smul.with.overflow.i4(i4 [[SIZE]], i4 [[NMEMB:%.*]])
10 ; CHECK-NEXT: [[SMUL_OV:%.*]] = extractvalue { i4, i1 } [[SMUL]], 1
11 ; CHECK-NEXT: [[PHITMP:%.*]] = xor i1 [[SMUL_OV]], true
12 ; CHECK-NEXT: [[OR:%.*]] = or i1 [[CMP]], [[PHITMP]]
13 ; CHECK-NEXT: ret i1 [[OR]]
15 %cmp = icmp eq i4 %size, 0
16 %smul = tail call { i4, i1 } @llvm.smul.with.overflow.i4(i4 %size, i4 %nmemb)
17 %smul.ov = extractvalue { i4, i1 } %smul, 1
18 %phitmp = xor i1 %smul.ov, true
19 %or = or i1 %cmp, %phitmp
23 define i1 @t1_commutative(i4 %size, i4 %nmemb) {
24 ; CHECK-LABEL: @t1_commutative(
25 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i4 [[SIZE:%.*]], 0
26 ; CHECK-NEXT: [[SMUL:%.*]] = tail call { i4, i1 } @llvm.smul.with.overflow.i4(i4 [[SIZE]], i4 [[NMEMB:%.*]])
27 ; CHECK-NEXT: [[SMUL_OV:%.*]] = extractvalue { i4, i1 } [[SMUL]], 1
28 ; CHECK-NEXT: [[PHITMP:%.*]] = xor i1 [[SMUL_OV]], true
29 ; CHECK-NEXT: [[OR:%.*]] = or i1 [[PHITMP]], [[CMP]]
30 ; CHECK-NEXT: ret i1 [[OR]]
32 %cmp = icmp eq i4 %size, 0
33 %smul = tail call { i4, i1 } @llvm.smul.with.overflow.i4(i4 %size, i4 %nmemb)
34 %smul.ov = extractvalue { i4, i1 } %smul, 1
35 %phitmp = xor i1 %smul.ov, true
36 %or = or i1 %phitmp, %cmp ; swapped
40 define i1 @n2_wrong_size(i4 %size0, i4 %size1, i4 %nmemb) {
41 ; CHECK-LABEL: @n2_wrong_size(
42 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i4 [[SIZE1:%.*]], 0
43 ; CHECK-NEXT: [[SMUL:%.*]] = tail call { i4, i1 } @llvm.smul.with.overflow.i4(i4 [[SIZE0:%.*]], i4 [[NMEMB:%.*]])
44 ; CHECK-NEXT: [[SMUL_OV:%.*]] = extractvalue { i4, i1 } [[SMUL]], 1
45 ; CHECK-NEXT: [[PHITMP:%.*]] = xor i1 [[SMUL_OV]], true
46 ; CHECK-NEXT: [[OR:%.*]] = or i1 [[CMP]], [[PHITMP]]
47 ; CHECK-NEXT: ret i1 [[OR]]
49 %cmp = icmp eq i4 %size1, 0 ; not %size0
50 %smul = tail call { i4, i1 } @llvm.smul.with.overflow.i4(i4 %size0, i4 %nmemb)
51 %smul.ov = extractvalue { i4, i1 } %smul, 1
52 %phitmp = xor i1 %smul.ov, true
53 %or = or i1 %cmp, %phitmp
57 define i1 @n3_wrong_pred(i4 %size, i4 %nmemb) {
58 ; CHECK-LABEL: @n3_wrong_pred(
59 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i4 [[SIZE:%.*]], 0
60 ; CHECK-NEXT: [[SMUL:%.*]] = tail call { i4, i1 } @llvm.smul.with.overflow.i4(i4 [[SIZE]], i4 [[NMEMB:%.*]])
61 ; CHECK-NEXT: [[SMUL_OV:%.*]] = extractvalue { i4, i1 } [[SMUL]], 1
62 ; CHECK-NEXT: [[PHITMP:%.*]] = xor i1 [[SMUL_OV]], true
63 ; CHECK-NEXT: [[OR:%.*]] = or i1 [[CMP]], [[PHITMP]]
64 ; CHECK-NEXT: ret i1 [[OR]]
66 %cmp = icmp ne i4 %size, 0 ; not 'eq'
67 %smul = tail call { i4, i1 } @llvm.smul.with.overflow.i4(i4 %size, i4 %nmemb)
68 %smul.ov = extractvalue { i4, i1 } %smul, 1
69 %phitmp = xor i1 %smul.ov, true
70 %or = or i1 %cmp, %phitmp
74 define i1 @n4_not_and(i4 %size, i4 %nmemb) {
75 ; CHECK-LABEL: @n4_not_and(
76 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i4 [[SIZE:%.*]], 0
77 ; CHECK-NEXT: [[SMUL:%.*]] = tail call { i4, i1 } @llvm.smul.with.overflow.i4(i4 [[SIZE]], i4 [[NMEMB:%.*]])
78 ; CHECK-NEXT: [[SMUL_OV:%.*]] = extractvalue { i4, i1 } [[SMUL]], 1
79 ; CHECK-NEXT: [[PHITMP:%.*]] = xor i1 [[SMUL_OV]], true
80 ; CHECK-NEXT: [[OR:%.*]] = and i1 [[CMP]], [[PHITMP]]
81 ; CHECK-NEXT: ret i1 [[OR]]
83 %cmp = icmp eq i4 %size, 0
84 %smul = tail call { i4, i1 } @llvm.smul.with.overflow.i4(i4 %size, i4 %nmemb)
85 %smul.ov = extractvalue { i4, i1 } %smul, 1
86 %phitmp = xor i1 %smul.ov, true
87 %or = and i1 %cmp, %phitmp ; not 'or'
91 define i1 @n5_not_zero(i4 %size, i4 %nmemb) {
92 ; CHECK-LABEL: @n5_not_zero(
93 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i4 [[SIZE:%.*]], 1
94 ; CHECK-NEXT: [[SMUL:%.*]] = tail call { i4, i1 } @llvm.smul.with.overflow.i4(i4 [[SIZE]], i4 [[NMEMB:%.*]])
95 ; CHECK-NEXT: [[SMUL_OV:%.*]] = extractvalue { i4, i1 } [[SMUL]], 1
96 ; CHECK-NEXT: [[PHITMP:%.*]] = xor i1 [[SMUL_OV]], true
97 ; CHECK-NEXT: [[OR:%.*]] = or i1 [[CMP]], [[PHITMP]]
98 ; CHECK-NEXT: ret i1 [[OR]]
100 %cmp = icmp eq i4 %size, 1 ; should be '0'
101 %smul = tail call { i4, i1 } @llvm.smul.with.overflow.i4(i4 %size, i4 %nmemb)
102 %smul.ov = extractvalue { i4, i1 } %smul, 1
103 %phitmp = xor i1 %smul.ov, true
104 %or = or i1 %cmp, %phitmp