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_umul(i4 %size, i4 %nmemb) {
7 ; CHECK-LABEL: @t0_umul(
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: [[PHITMP:%.*]] = xor i1 [[SMUL_OV]], true
11 ; CHECK-NEXT: ret i1 [[PHITMP]]
13 %cmp = icmp eq i4 %size, 0
14 %smul = tail call { i4, i1 } @llvm.smul.with.overflow.i4(i4 %size, i4 %nmemb)
15 %smul.ov = extractvalue { i4, i1 } %smul, 1
16 %phitmp = xor i1 %smul.ov, true
17 %or = or i1 %cmp, %phitmp
21 define i1 @t1_commutative(i4 %size, i4 %nmemb) {
22 ; CHECK-LABEL: @t1_commutative(
23 ; CHECK-NEXT: [[SMUL:%.*]] = tail call { i4, i1 } @llvm.smul.with.overflow.i4(i4 [[SIZE:%.*]], i4 [[NMEMB:%.*]])
24 ; CHECK-NEXT: [[SMUL_OV:%.*]] = extractvalue { i4, i1 } [[SMUL]], 1
25 ; CHECK-NEXT: [[PHITMP:%.*]] = xor i1 [[SMUL_OV]], true
26 ; CHECK-NEXT: ret i1 [[PHITMP]]
28 %cmp = icmp eq i4 %size, 0
29 %smul = tail call { i4, i1 } @llvm.smul.with.overflow.i4(i4 %size, i4 %nmemb)
30 %smul.ov = extractvalue { i4, i1 } %smul, 1
31 %phitmp = xor i1 %smul.ov, true
32 %or = or i1 %phitmp, %cmp ; swapped
36 define i1 @n2_wrong_size(i4 %size0, i4 %size1, i4 %nmemb) {
37 ; CHECK-LABEL: @n2_wrong_size(
38 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i4 [[SIZE1:%.*]], 0
39 ; CHECK-NEXT: [[SMUL:%.*]] = tail call { i4, i1 } @llvm.smul.with.overflow.i4(i4 [[SIZE0:%.*]], i4 [[NMEMB:%.*]])
40 ; CHECK-NEXT: [[SMUL_OV:%.*]] = extractvalue { i4, i1 } [[SMUL]], 1
41 ; CHECK-NEXT: [[PHITMP:%.*]] = xor i1 [[SMUL_OV]], true
42 ; CHECK-NEXT: [[OR:%.*]] = or i1 [[CMP]], [[PHITMP]]
43 ; CHECK-NEXT: ret i1 [[OR]]
45 %cmp = icmp eq i4 %size1, 0 ; not %size0
46 %smul = tail call { i4, i1 } @llvm.smul.with.overflow.i4(i4 %size0, i4 %nmemb)
47 %smul.ov = extractvalue { i4, i1 } %smul, 1
48 %phitmp = xor i1 %smul.ov, true
49 %or = or i1 %cmp, %phitmp
53 define i1 @n3_wrong_pred(i4 %size, i4 %nmemb) {
54 ; CHECK-LABEL: @n3_wrong_pred(
55 ; CHECK-NEXT: ret i1 true
57 %cmp = icmp ne i4 %size, 0 ; not 'eq'
58 %smul = tail call { i4, i1 } @llvm.smul.with.overflow.i4(i4 %size, i4 %nmemb)
59 %smul.ov = extractvalue { i4, i1 } %smul, 1
60 %phitmp = xor i1 %smul.ov, true
61 %or = or i1 %cmp, %phitmp
65 define i1 @n4_not_and(i4 %size, i4 %nmemb) {
66 ; CHECK-LABEL: @n4_not_and(
67 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i4 [[SIZE:%.*]], 0
68 ; CHECK-NEXT: ret i1 [[CMP]]
70 %cmp = icmp eq 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 %phitmp = xor i1 %smul.ov, true
74 %or = and i1 %cmp, %phitmp ; not 'or'
78 define i1 @n5_not_zero(i4 %size, i4 %nmemb) {
79 ; CHECK-LABEL: @n5_not_zero(
80 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i4 [[SIZE:%.*]], 1
81 ; CHECK-NEXT: [[SMUL:%.*]] = tail call { i4, i1 } @llvm.smul.with.overflow.i4(i4 [[SIZE]], i4 [[NMEMB:%.*]])
82 ; CHECK-NEXT: [[SMUL_OV:%.*]] = extractvalue { i4, i1 } [[SMUL]], 1
83 ; CHECK-NEXT: [[PHITMP:%.*]] = xor i1 [[SMUL_OV]], true
84 ; CHECK-NEXT: [[OR:%.*]] = or i1 [[CMP]], [[PHITMP]]
85 ; CHECK-NEXT: ret i1 [[OR]]
87 %cmp = icmp eq i4 %size, 1 ; should be '0'
88 %smul = tail call { i4, i1 } @llvm.smul.with.overflow.i4(i4 %size, i4 %nmemb)
89 %smul.ov = extractvalue { i4, i1 } %smul, 1
90 %phitmp = xor i1 %smul.ov, true
91 %or = or i1 %cmp, %phitmp