1; RUN: opt -S -instcombine < %s | FileCheck %s
2
3; rdar://12182093
4
5target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
6target triple = "x86_64-apple-macosx10.8.0"
7
8; CHECK-LABEL: @udiv400(
9; CHECK: udiv i32 %x, 400
10; CHECK: ret
11define i32 @udiv400(i32 %x) {
12entry:
13  %div = lshr i32 %x, 2
14  %div1 = udiv i32 %div, 100
15  ret i32 %div1
16}
17
18
19; CHECK-LABEL: @udiv400_no(
20; CHECK: ashr
21; CHECK: div
22; CHECK: ret
23define i32 @udiv400_no(i32 %x) {
24entry:
25  %div = ashr i32 %x, 2
26  %div1 = udiv i32 %div, 100
27  ret i32 %div1
28}
29
30; CHECK-LABEL: @sdiv400_yes(
31; CHECK: udiv i32 %x, 400
32; CHECK: ret
33define i32 @sdiv400_yes(i32 %x) {
34entry:
35  %div = lshr i32 %x, 2
36  ; The sign bits of both operands are zero (i.e. we can prove they are
37  ; unsigned inputs), turn this into a udiv.
38  ; Next, optimize this just like sdiv.
39  %div1 = sdiv i32 %div, 100
40  ret i32 %div1
41}
42
43
44; CHECK-LABEL: @udiv_i80(
45; CHECK: udiv i80 %x, 400
46; CHECK: ret
47define i80 @udiv_i80(i80 %x) {
48  %div = lshr i80 %x, 2
49  %div1 = udiv i80 %div, 100
50  ret i80 %div1
51}
52
53define i32 @no_crash_notconst_udiv(i32 %x, i32 %notconst) {
54  %div = lshr i32 %x, %notconst
55  %div1 = udiv i32 %div, 100
56  ret i32 %div1
57}
58