1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
4 declare { i64, i1 } @llvm.smul.with.overflow.i64(i64, i64)
5 declare { i8, i1 } @llvm.smul.with.overflow.i8(i8, i8)
7 define i1 @test_generic(i64 %a, i64 %b) {
8 ; CHECK-LABEL: @test_generic(
9 ; CHECK-NEXT: [[RES:%.*]] = tail call { i64, i1 } @llvm.smul.with.overflow.i64(i64 [[A:%.*]], i64 [[B:%.*]])
10 ; CHECK-NEXT: [[OVERFLOW:%.*]] = extractvalue { i64, i1 } [[RES]], 1
11 ; CHECK-NEXT: ret i1 [[OVERFLOW]]
13 %res = tail call { i64, i1 } @llvm.smul.with.overflow.i64(i64 %a, i64 %b)
14 %overflow = extractvalue { i64, i1 } %res, 1
18 define i1 @test_constant0(i8 %a) {
19 ; CHECK-LABEL: @test_constant0(
20 ; CHECK-NEXT: ret i1 false
22 %res = tail call { i8, i1 } @llvm.smul.with.overflow.i8(i8 %a, i8 0)
23 %overflow = extractvalue { i8, i1 } %res, 1
27 define i1 @test_constant1(i8 %a) {
28 ; CHECK-LABEL: @test_constant1(
29 ; CHECK-NEXT: ret i1 false
31 %res = tail call { i8, i1 } @llvm.smul.with.overflow.i8(i8 %a, i8 1)
32 %overflow = extractvalue { i8, i1 } %res, 1
36 define i1 @test_constant2(i8 %a) {
37 ; CHECK-LABEL: @test_constant2(
38 ; CHECK-NEXT: [[TMP1:%.*]] = add i8 [[A:%.*]], 64
39 ; CHECK-NEXT: [[OVERFLOW:%.*]] = icmp slt i8 [[TMP1]], 0
40 ; CHECK-NEXT: ret i1 [[OVERFLOW]]
42 %res = tail call { i8, i1 } @llvm.smul.with.overflow.i8(i8 %a, i8 2)
43 %overflow = extractvalue { i8, i1 } %res, 1
47 define i1 @test_constant3(i8 %a) {
48 ; CHECK-LABEL: @test_constant3(
49 ; CHECK-NEXT: [[TMP1:%.*]] = add i8 [[A:%.*]], 42
50 ; CHECK-NEXT: [[OVERFLOW:%.*]] = icmp ugt i8 [[TMP1]], 84
51 ; CHECK-NEXT: ret i1 [[OVERFLOW]]
53 %res = tail call { i8, i1 } @llvm.smul.with.overflow.i8(i8 %a, i8 3)
54 %overflow = extractvalue { i8, i1 } %res, 1
58 define i1 @test_constant4(i8 %a) {
59 ; CHECK-LABEL: @test_constant4(
60 ; CHECK-NEXT: [[TMP1:%.*]] = add i8 [[A:%.*]], 32
61 ; CHECK-NEXT: [[OVERFLOW:%.*]] = icmp ugt i8 [[TMP1]], 63
62 ; CHECK-NEXT: ret i1 [[OVERFLOW]]
64 %res = tail call { i8, i1 } @llvm.smul.with.overflow.i8(i8 %a, i8 4)
65 %overflow = extractvalue { i8, i1 } %res, 1
70 define i1 @test_constant127(i8 %a) {
71 ; CHECK-LABEL: @test_constant127(
72 ; CHECK-NEXT: [[TMP1:%.*]] = add i8 [[A:%.*]], 1
73 ; CHECK-NEXT: [[OVERFLOW:%.*]] = icmp ugt i8 [[TMP1]], 2
74 ; CHECK-NEXT: ret i1 [[OVERFLOW]]
76 %res = tail call { i8, i1 } @llvm.smul.with.overflow.i8(i8 %a, i8 127)
77 %overflow = extractvalue { i8, i1 } %res, 1
81 define i1 @test_constant128(i8 %a) {
82 ; CHECK-LABEL: @test_constant128(
83 ; CHECK-NEXT: [[OVERFLOW:%.*]] = icmp ugt i8 [[A:%.*]], 1
84 ; CHECK-NEXT: ret i1 [[OVERFLOW]]
86 %res = tail call { i8, i1 } @llvm.smul.with.overflow.i8(i8 %a, i8 128)
87 %overflow = extractvalue { i8, i1 } %res, 1
91 define i1 @test_constant255(i8 %a) {
92 ; CHECK-LABEL: @test_constant255(
93 ; CHECK-NEXT: [[OVERFLOW:%.*]] = icmp eq i8 [[A:%.*]], -128
94 ; CHECK-NEXT: ret i1 [[OVERFLOW]]
96 %res = tail call { i8, i1 } @llvm.smul.with.overflow.i8(i8 %a, i8 255)
97 %overflow = extractvalue { i8, i1 } %res, 1