xref: /minix3/external/bsd/llvm/dist/llvm/test/CodeGen/X86/divide-by-constant.ll (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc; RUN: llc < %s -mcpu=generic -mtriple=i686-pc-linux-gnu -asm-verbose=0 | FileCheck %s
2f4a2713aSLionel Sambuctarget datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32"
3f4a2713aSLionel Sambuctarget triple = "i686-pc-linux-gnu"
4f4a2713aSLionel Sambuc
5f4a2713aSLionel Sambucdefine zeroext i16 @test1(i16 zeroext %x) nounwind {
6f4a2713aSLionel Sambucentry:
7f4a2713aSLionel Sambuc	%div = udiv i16 %x, 33
8f4a2713aSLionel Sambuc	ret i16 %div
9f4a2713aSLionel Sambuc; CHECK-LABEL: test1:
10*0a6a1f1dSLionel Sambuc; CHECK: imull	$63551, %eax
11f4a2713aSLionel Sambuc; CHECK-NEXT: shrl	$21, %eax
12f4a2713aSLionel Sambuc; CHECK-NEXT: ret
13f4a2713aSLionel Sambuc}
14f4a2713aSLionel Sambuc
15f4a2713aSLionel Sambucdefine zeroext i16 @test2(i8 signext %x, i16 zeroext %c) nounwind readnone ssp noredzone {
16f4a2713aSLionel Sambucentry:
17f4a2713aSLionel Sambuc  %div = udiv i16 %c, 3
18f4a2713aSLionel Sambuc  ret i16 %div
19f4a2713aSLionel Sambuc
20f4a2713aSLionel Sambuc; CHECK-LABEL: test2:
21*0a6a1f1dSLionel Sambuc; CHECK: imull	$43691, %eax
22f4a2713aSLionel Sambuc; CHECK-NEXT: shrl	$17, %eax
23f4a2713aSLionel Sambuc; CHECK-NEXT: ret
24f4a2713aSLionel Sambuc}
25f4a2713aSLionel Sambuc
26f4a2713aSLionel Sambucdefine zeroext i8 @test3(i8 zeroext %x, i8 zeroext %c) nounwind readnone ssp noredzone {
27f4a2713aSLionel Sambucentry:
28f4a2713aSLionel Sambuc  %div = udiv i8 %c, 3
29f4a2713aSLionel Sambuc  ret i8 %div
30f4a2713aSLionel Sambuc
31f4a2713aSLionel Sambuc; CHECK-LABEL: test3:
32f4a2713aSLionel Sambuc; CHECK: movzbl  8(%esp), %eax
33*0a6a1f1dSLionel Sambuc; CHECK-NEXT: imull	$171, %eax
34*0a6a1f1dSLionel Sambuc; CHECK-NEXT: andl $65024, %eax
35f4a2713aSLionel Sambuc; CHECK-NEXT: shrl	$9, %eax
36f4a2713aSLionel Sambuc; CHECK-NEXT: ret
37f4a2713aSLionel Sambuc}
38f4a2713aSLionel Sambuc
39f4a2713aSLionel Sambucdefine signext i16 @test4(i16 signext %x) nounwind {
40f4a2713aSLionel Sambucentry:
41f4a2713aSLionel Sambuc	%div = sdiv i16 %x, 33		; <i32> [#uses=1]
42f4a2713aSLionel Sambuc	ret i16 %div
43f4a2713aSLionel Sambuc; CHECK-LABEL: test4:
44*0a6a1f1dSLionel Sambuc; CHECK: imull	$1986, %eax
45f4a2713aSLionel Sambuc}
46f4a2713aSLionel Sambuc
47f4a2713aSLionel Sambucdefine i32 @test5(i32 %A) nounwind {
48f4a2713aSLionel Sambuc        %tmp1 = udiv i32 %A, 1577682821         ; <i32> [#uses=1]
49f4a2713aSLionel Sambuc        ret i32 %tmp1
50f4a2713aSLionel Sambuc; CHECK-LABEL: test5:
51f4a2713aSLionel Sambuc; CHECK: movl	$365384439, %eax
52f4a2713aSLionel Sambuc; CHECK: mull	4(%esp)
53f4a2713aSLionel Sambuc}
54f4a2713aSLionel Sambuc
55f4a2713aSLionel Sambucdefine signext i16 @test6(i16 signext %x) nounwind {
56f4a2713aSLionel Sambucentry:
57f4a2713aSLionel Sambuc  %div = sdiv i16 %x, 10
58f4a2713aSLionel Sambuc  ret i16 %div
59f4a2713aSLionel Sambuc; CHECK-LABEL: test6:
60*0a6a1f1dSLionel Sambuc; CHECK: imull $26215, %eax
61*0a6a1f1dSLionel Sambuc; CHECK: movl %eax, %ecx
62*0a6a1f1dSLionel Sambuc; CHECK: shrl $31, %ecx
63*0a6a1f1dSLionel Sambuc; CHECK: sarl $18, %eax
64f4a2713aSLionel Sambuc}
65f4a2713aSLionel Sambuc
66f4a2713aSLionel Sambucdefine i32 @test7(i32 %x) nounwind {
67f4a2713aSLionel Sambuc  %div = udiv i32 %x, 28
68f4a2713aSLionel Sambuc  ret i32 %div
69f4a2713aSLionel Sambuc; CHECK-LABEL: test7:
70f4a2713aSLionel Sambuc; CHECK: shrl $2
71f4a2713aSLionel Sambuc; CHECK: movl $613566757
72f4a2713aSLionel Sambuc; CHECK: mull
73f4a2713aSLionel Sambuc; CHECK-NOT: shrl
74f4a2713aSLionel Sambuc; CHECK: ret
75f4a2713aSLionel Sambuc}
76f4a2713aSLionel Sambuc
77f4a2713aSLionel Sambuc; PR13326
78f4a2713aSLionel Sambucdefine i8 @test8(i8 %x) nounwind {
79f4a2713aSLionel Sambuc  %div = udiv i8 %x, 78
80f4a2713aSLionel Sambuc  ret i8 %div
81f4a2713aSLionel Sambuc; CHECK-LABEL: test8:
82f4a2713aSLionel Sambuc; CHECK: shrb %
83f4a2713aSLionel Sambuc; CHECK: imull $211
84f4a2713aSLionel Sambuc; CHECK: shrl $13
85f4a2713aSLionel Sambuc; CHECK: ret
86f4a2713aSLionel Sambuc}
87f4a2713aSLionel Sambuc
88f4a2713aSLionel Sambucdefine i8 @test9(i8 %x) nounwind {
89f4a2713aSLionel Sambuc  %div = udiv i8 %x, 116
90f4a2713aSLionel Sambuc  ret i8 %div
91f4a2713aSLionel Sambuc; CHECK-LABEL: test9:
92f4a2713aSLionel Sambuc; CHECK: shrb $2
93f4a2713aSLionel Sambuc; CHECK: imull $71
94f4a2713aSLionel Sambuc; CHECK: shrl $11
95f4a2713aSLionel Sambuc; CHECK: ret
96f4a2713aSLionel Sambuc}
97