1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=m68k-linux -verify-machineinstrs | FileCheck %s
4 declare i32 @printf(i8*, ...) nounwind
5 declare {i32, i1} @llvm.smul.with.overflow.i32(i32, i32)
6 declare { i63, i1 } @llvm.smul.with.overflow.i63(i63, i63)
8 @ok = internal constant [4 x i8] c"%d\0A\00"
9 @no = internal constant [4 x i8] c"no\0A\00"
11 define fastcc i1 @test1(i32 %v1, i32 %v2) nounwind {
13 ; CHECK: ; %bb.0: ; %entry
14 ; CHECK-NEXT: suba.l #28, %sp
15 ; CHECK-NEXT: movem.l %d2-%d3, (20,%sp) ; 12-byte Folded Spill
16 ; CHECK-NEXT: move.l %d1, (12,%sp)
17 ; CHECK-NEXT: move.l #31, %d2
18 ; CHECK-NEXT: asr.l %d2, %d1
19 ; CHECK-NEXT: move.l %d1, (8,%sp)
20 ; CHECK-NEXT: move.l %d0, (4,%sp)
21 ; CHECK-NEXT: asr.l %d2, %d0
22 ; CHECK-NEXT: move.l %d0, (%sp)
23 ; CHECK-NEXT: jsr __muldi3@PLT
24 ; CHECK-NEXT: move.l %d1, %d3
25 ; CHECK-NEXT: asr.l %d2, %d3
26 ; CHECK-NEXT: sub.l %d3, %d0
28 ; CHECK-NEXT: cmpi.b #0, %d0
29 ; CHECK-NEXT: beq .LBB0_1
30 ; CHECK-NEXT: ; %bb.2: ; %overflow
31 ; CHECK-NEXT: lea (no,%pc), %a0
32 ; CHECK-NEXT: move.l %a0, (%sp)
33 ; CHECK-NEXT: jsr printf@PLT
34 ; CHECK-NEXT: move.b #0, %d0
35 ; CHECK-NEXT: bra .LBB0_3
36 ; CHECK-NEXT: .LBB0_1: ; %normal
37 ; CHECK-NEXT: move.l %d1, (4,%sp)
38 ; CHECK-NEXT: lea (ok,%pc), %a0
39 ; CHECK-NEXT: move.l %a0, (%sp)
40 ; CHECK-NEXT: jsr printf@PLT
41 ; CHECK-NEXT: move.b #1, %d0
42 ; CHECK-NEXT: .LBB0_3: ; %overflow
43 ; CHECK-NEXT: movem.l (20,%sp), %d2-%d3 ; 12-byte Folded Reload
44 ; CHECK-NEXT: adda.l #28, %sp
47 %t = call {i32, i1} @llvm.smul.with.overflow.i32(i32 %v1, i32 %v2)
48 %sum = extractvalue {i32, i1} %t, 0
49 %obit = extractvalue {i32, i1} %t, 1
50 br i1 %obit, label %overflow, label %normal
53 %t1 = tail call i32 (i8*, ...) @printf( i8* getelementptr ([4 x i8], [4 x i8]* @ok, i32 0, i32 0), i32 %sum ) nounwind
57 %t2 = tail call i32 (i8*, ...) @printf( i8* getelementptr ([4 x i8], [4 x i8]* @no, i32 0, i32 0) ) nounwind
61 define fastcc i1 @test2(i32 %v1, i32 %v2) nounwind {
63 ; CHECK: ; %bb.0: ; %entry
64 ; CHECK-NEXT: suba.l #28, %sp
65 ; CHECK-NEXT: movem.l %d2-%d3, (20,%sp) ; 12-byte Folded Spill
66 ; CHECK-NEXT: move.l %d1, (12,%sp)
67 ; CHECK-NEXT: move.l #31, %d2
68 ; CHECK-NEXT: asr.l %d2, %d1
69 ; CHECK-NEXT: move.l %d1, (8,%sp)
70 ; CHECK-NEXT: move.l %d0, (4,%sp)
71 ; CHECK-NEXT: asr.l %d2, %d0
72 ; CHECK-NEXT: move.l %d0, (%sp)
73 ; CHECK-NEXT: jsr __muldi3@PLT
74 ; CHECK-NEXT: move.l %d1, %d3
75 ; CHECK-NEXT: asr.l %d2, %d3
76 ; CHECK-NEXT: sub.l %d3, %d0
78 ; CHECK-NEXT: sub.b #1, %d0
79 ; CHECK-NEXT: bne .LBB1_3
80 ; CHECK-NEXT: ; %bb.1: ; %overflow
81 ; CHECK-NEXT: lea (no,%pc), %a0
82 ; CHECK-NEXT: move.l %a0, (%sp)
83 ; CHECK-NEXT: jsr printf@PLT
84 ; CHECK-NEXT: move.b #0, %d0
85 ; CHECK-NEXT: bra .LBB1_2
86 ; CHECK-NEXT: .LBB1_3: ; %normal
87 ; CHECK-NEXT: move.l %d1, (4,%sp)
88 ; CHECK-NEXT: lea (ok,%pc), %a0
89 ; CHECK-NEXT: move.l %a0, (%sp)
90 ; CHECK-NEXT: jsr printf@PLT
91 ; CHECK-NEXT: move.b #1, %d0
92 ; CHECK-NEXT: .LBB1_2: ; %overflow
93 ; CHECK-NEXT: movem.l (20,%sp), %d2-%d3 ; 12-byte Folded Reload
94 ; CHECK-NEXT: adda.l #28, %sp
97 %t = call {i32, i1} @llvm.smul.with.overflow.i32(i32 %v1, i32 %v2)
98 %sum = extractvalue {i32, i1} %t, 0
99 %obit = extractvalue {i32, i1} %t, 1
100 br i1 %obit, label %overflow, label %normal
103 %t2 = tail call i32 (i8*, ...) @printf( i8* getelementptr ([4 x i8], [4 x i8]* @no, i32 0, i32 0) ) nounwind
107 %t1 = tail call i32 (i8*, ...) @printf( i8* getelementptr ([4 x i8], [4 x i8]* @ok, i32 0, i32 0), i32 %sum ) nounwind
111 define i32 @test3(i32 %a, i32 %b) nounwind readnone {
112 ; CHECK-LABEL: test3:
113 ; CHECK: ; %bb.0: ; %entry
114 ; CHECK-NEXT: move.l (8,%sp), %d0
115 ; CHECK-NEXT: add.l (4,%sp), %d0
116 ; CHECK-NEXT: add.l %d0, %d0
119 %tmp0 = add i32 %b, %a
120 %tmp1 = call { i32, i1 } @llvm.smul.with.overflow.i32(i32 %tmp0, i32 2)
121 %tmp2 = extractvalue { i32, i1 } %tmp1, 0
125 ; Same as umul-with-overflow, we shouldn't fallback to
127 define i32 @test4(i32 %a, i32 %b) nounwind readnone {
128 ; CHECK-LABEL: test4:
129 ; CHECK: ; %bb.0: ; %entry
130 ; CHECK-NEXT: move.l (8,%sp), %d0
131 ; CHECK-NEXT: add.l (4,%sp), %d0
132 ; CHECK-NEXT: lsl.l #2, %d0
135 %tmp0 = add i32 %b, %a
136 %tmp1 = call { i32, i1 } @llvm.smul.with.overflow.i32(i32 %tmp0, i32 4)
137 %tmp2 = extractvalue { i32, i1 } %tmp1, 0