blob: 2f0986e831e27febaf466367be94fc96090629aa [file] [log] [blame]
Eric Christopher362fee92011-06-17 20:41:29 +00001; RUN: llc < %s -mtriple=x86_64-apple-darwin | FileCheck %s
2%0 = type { i64, i64 }
3%1 = type { i128, i1 }
4
Eric Christopher362fee92011-06-17 20:41:29 +00005define %0 @x(i64 %a.coerce0, i64 %a.coerce1, i64 %b.coerce0, i64 %b.coerce1) nounwind uwtable ssp {
Eric Christophera3071452011-06-18 00:09:57 +00006; CHECK: x
Eric Christopher362fee92011-06-17 20:41:29 +00007entry:
8 %tmp16 = zext i64 %a.coerce0 to i128
9 %tmp11 = zext i64 %a.coerce1 to i128
10 %tmp12 = shl nuw i128 %tmp11, 64
11 %ins14 = or i128 %tmp12, %tmp16
12 %tmp6 = zext i64 %b.coerce0 to i128
13 %tmp3 = zext i64 %b.coerce1 to i128
14 %tmp4 = shl nuw i128 %tmp3, 64
15 %ins = or i128 %tmp4, %tmp6
16 %0 = tail call %1 @llvm.smul.with.overflow.i128(i128 %ins14, i128 %ins)
17; CHECK: callq ___muloti4
18 %1 = extractvalue %1 %0, 0
19 %2 = extractvalue %1 %0, 1
20 br i1 %2, label %overflow, label %nooverflow
21
22overflow: ; preds = %entry
23 tail call void @llvm.trap()
24 unreachable
25
26nooverflow: ; preds = %entry
27 %tmp20 = trunc i128 %1 to i64
28 %tmp21 = insertvalue %0 undef, i64 %tmp20, 0
29 %tmp22 = lshr i128 %1, 64
30 %tmp23 = trunc i128 %tmp22 to i64
31 %tmp24 = insertvalue %0 %tmp21, i64 %tmp23, 1
32 ret %0 %tmp24
33}
34
Eric Christophera3071452011-06-18 00:09:57 +000035define %0 @foo(i64 %a.coerce0, i64 %a.coerce1, i64 %b.coerce0, i64 %b.coerce1) nounwind uwtable ssp {
36entry:
37; CHECK: foo
38 %retval = alloca i128, align 16
39 %coerce = alloca i128, align 16
40 %a.addr = alloca i128, align 16
41 %coerce1 = alloca i128, align 16
42 %b.addr = alloca i128, align 16
43 %0 = bitcast i128* %coerce to %0*
44 %1 = getelementptr %0* %0, i32 0, i32 0
45 store i64 %a.coerce0, i64* %1
46 %2 = getelementptr %0* %0, i32 0, i32 1
47 store i64 %a.coerce1, i64* %2
48 %a = load i128* %coerce, align 16
49 store i128 %a, i128* %a.addr, align 16
50 %3 = bitcast i128* %coerce1 to %0*
51 %4 = getelementptr %0* %3, i32 0, i32 0
52 store i64 %b.coerce0, i64* %4
53 %5 = getelementptr %0* %3, i32 0, i32 1
54 store i64 %b.coerce1, i64* %5
55 %b = load i128* %coerce1, align 16
56 store i128 %b, i128* %b.addr, align 16
57 %tmp = load i128* %a.addr, align 16
58 %tmp2 = load i128* %b.addr, align 16
59 %6 = call %1 @llvm.umul.with.overflow.i128(i128 %tmp, i128 %tmp2)
60; CHECK: cmov
61; CHECK: divti3
62 %7 = extractvalue %1 %6, 0
63 %8 = extractvalue %1 %6, 1
64 br i1 %8, label %overflow, label %nooverflow
65
66overflow: ; preds = %entry
67 call void @llvm.trap()
68 unreachable
69
70nooverflow: ; preds = %entry
71 store i128 %7, i128* %retval
72 %9 = bitcast i128* %retval to %0*
73 %10 = load %0* %9, align 1
74 ret %0 %10
75}
76
77declare %1 @llvm.umul.with.overflow.i128(i128, i128) nounwind readnone
78
Eric Christopher362fee92011-06-17 20:41:29 +000079declare %1 @llvm.smul.with.overflow.i128(i128, i128) nounwind readnone
80
81declare void @llvm.trap() nounwind