OSDN Git Service

7f5ff06e5948ef898b634cca2b2db7041b34ec5f
[android-x86/external-llvm.git] / test / Transforms / InstCombine / sdiv-canonicalize.ll
1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
3
4 define i32 @test_sdiv_canonicalize_op0(i32 %x, i32 %y) {
5 ; CHECK-LABEL: @test_sdiv_canonicalize_op0(
6 ; CHECK-NEXT:    [[NEG:%.*]] = sub nsw i32 0, [[X:%.*]]
7 ; CHECK-NEXT:    [[SDIV:%.*]] = sdiv i32 [[NEG]], [[Y:%.*]]
8 ; CHECK-NEXT:    ret i32 [[SDIV]]
9 ;
10   %neg = sub nsw i32 0, %x
11   %sdiv = sdiv i32 %neg, %y
12   ret i32 %sdiv
13 }
14
15 define i32 @test_sdiv_canonicalize_op1(i32 %x, i32 %z) {
16 ; CHECK-LABEL: @test_sdiv_canonicalize_op1(
17 ; CHECK-NEXT:    [[Y:%.*]] = mul i32 [[Z:%.*]], 3
18 ; CHECK-NEXT:    [[NEG:%.*]] = sub nsw i32 0, [[X:%.*]]
19 ; CHECK-NEXT:    [[SDIV:%.*]] = sdiv i32 [[Y]], [[NEG]]
20 ; CHECK-NEXT:    ret i32 [[SDIV]]
21 ;
22   %y = mul i32 %z, 3
23   %neg = sub nsw i32 0, %x
24   %sdiv = sdiv i32 %y, %neg
25   ret i32 %sdiv
26 }
27
28 define i32 @test_sdiv_canonicalize_nonsw(i32 %x, i32 %y) {
29 ; CHECK-LABEL: @test_sdiv_canonicalize_nonsw(
30 ; CHECK-NEXT:    [[NEG:%.*]] = sub i32 0, [[X:%.*]]
31 ; CHECK-NEXT:    [[SDIV:%.*]] = sdiv i32 [[NEG]], [[Y:%.*]]
32 ; CHECK-NEXT:    ret i32 [[SDIV]]
33 ;
34   %neg = sub i32 0, %x
35   %sdiv = sdiv i32 %neg, %y
36   ret i32 %sdiv
37 }
38
39 define <2 x i32> @test_sdiv_canonicalize_vec(<2 x i32> %x, <2 x i32> %y) {
40 ; CHECK-LABEL: @test_sdiv_canonicalize_vec(
41 ; CHECK-NEXT:    [[NEG:%.*]] = sub nsw <2 x i32> zeroinitializer, [[X:%.*]]
42 ; CHECK-NEXT:    [[SDIV:%.*]] = sdiv <2 x i32> [[NEG]], [[Y:%.*]]
43 ; CHECK-NEXT:    ret <2 x i32> [[SDIV]]
44 ;
45   %neg = sub nsw <2 x i32> <i32 0, i32 0>, %x
46   %sdiv = sdiv <2 x i32> %neg, %y
47   ret <2 x i32> %sdiv
48 }
49
50 define i32 @test_sdiv_canonicalize_multiple_uses(i32 %x, i32 %y) {
51 ; CHECK-LABEL: @test_sdiv_canonicalize_multiple_uses(
52 ; CHECK-NEXT:    [[NEG:%.*]] = sub nsw i32 0, [[X:%.*]]
53 ; CHECK-NEXT:    [[SDIV:%.*]] = sdiv i32 [[NEG]], [[Y:%.*]]
54 ; CHECK-NEXT:    [[SDIV2:%.*]] = sdiv i32 [[SDIV]], [[NEG]]
55 ; CHECK-NEXT:    ret i32 [[SDIV2]]
56 ;
57   %neg = sub nsw i32 0, %x
58   %sdiv = sdiv i32 %neg, %y
59   %sdiv2 = sdiv i32 %sdiv, %neg
60   ret i32 %sdiv2
61 }
62
63 ; There is combination: (X/-CE) -> -(X/CE)
64 ; There is another combination: -(X/CE) -> (X/-CE)
65 ; Make sure don't combine them endless.
66
67 @X = global i32 5
68
69 define i64 @test_sdiv_canonicalize_constexpr(i64 %L1) {
70 ; currently opt folds (sub nsw i64 0, constexpr) -> (sub i64, 0, constexpr).
71 ; sdiv canonicalize requires a nsw sub.
72 ; CHECK-LABEL: @test_sdiv_canonicalize_constexpr(
73 ; CHECK-NEXT:    [[B4:%.*]] = sdiv i64 [[L1:%.*]], sub (i64 0, i64 ptrtoint (i32* @X to i64))
74 ; CHECK-NEXT:    ret i64 [[B4]]
75 ;
76   %v1 = ptrtoint i32* @X to i64
77   %B8 = sub nsw i64 0, %v1
78   %B4 = sdiv i64 %L1, %B8
79   ret i64 %B4
80 }