147
|
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: [[SDIV1:%.*]] = sdiv i32 [[X:%.*]], [[Y:%.*]]
|
|
7 ; CHECK-NEXT: [[SDIV:%.*]] = sub nsw i32 0, [[SDIV1]]
|
|
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_op0_exact(i32 %x, i32 %y) {
|
|
16 ; CHECK-LABEL: @test_sdiv_canonicalize_op0_exact(
|
|
17 ; CHECK-NEXT: [[SDIV1:%.*]] = sdiv exact i32 [[X:%.*]], [[Y:%.*]]
|
|
18 ; CHECK-NEXT: [[SDIV:%.*]] = sub nsw i32 0, [[SDIV1]]
|
|
19 ; CHECK-NEXT: ret i32 [[SDIV]]
|
|
20 ;
|
|
21 %neg = sub nsw i32 0, %x
|
|
22 %sdiv = sdiv exact i32 %neg, %y
|
|
23 ret i32 %sdiv
|
|
24 }
|
|
25
|
|
26 ; (X/-Y) is not equal to -(X/Y), don't canonicalize.
|
|
27 define i32 @test_sdiv_canonicalize_op1(i32 %x, i32 %z) {
|
|
28 ; CHECK-LABEL: @test_sdiv_canonicalize_op1(
|
|
29 ; CHECK-NEXT: [[Y:%.*]] = mul i32 [[Z:%.*]], 3
|
|
30 ; CHECK-NEXT: [[NEG:%.*]] = sub nsw i32 0, [[X:%.*]]
|
|
31 ; CHECK-NEXT: [[SDIV:%.*]] = sdiv i32 [[Y]], [[NEG]]
|
|
32 ; CHECK-NEXT: ret i32 [[SDIV]]
|
|
33 ;
|
|
34 %y = mul i32 %z, 3
|
|
35 %neg = sub nsw i32 0, %x
|
|
36 %sdiv = sdiv i32 %y, %neg
|
|
37 ret i32 %sdiv
|
|
38 }
|
|
39
|
|
40 define i32 @test_sdiv_canonicalize_nonsw(i32 %x, i32 %y) {
|
|
41 ; CHECK-LABEL: @test_sdiv_canonicalize_nonsw(
|
|
42 ; CHECK-NEXT: [[NEG:%.*]] = sub i32 0, [[X:%.*]]
|
|
43 ; CHECK-NEXT: [[SDIV:%.*]] = sdiv i32 [[NEG]], [[Y:%.*]]
|
|
44 ; CHECK-NEXT: ret i32 [[SDIV]]
|
|
45 ;
|
|
46 %neg = sub i32 0, %x
|
|
47 %sdiv = sdiv i32 %neg, %y
|
|
48 ret i32 %sdiv
|
|
49 }
|
|
50
|
|
51 define <2 x i32> @test_sdiv_canonicalize_vec(<2 x i32> %x, <2 x i32> %y) {
|
|
52 ; CHECK-LABEL: @test_sdiv_canonicalize_vec(
|
|
53 ; CHECK-NEXT: [[SDIV1:%.*]] = sdiv <2 x i32> [[X:%.*]], [[Y:%.*]]
|
|
54 ; CHECK-NEXT: [[SDIV:%.*]] = sub nsw <2 x i32> zeroinitializer, [[SDIV1]]
|
|
55 ; CHECK-NEXT: ret <2 x i32> [[SDIV]]
|
|
56 ;
|
|
57 %neg = sub nsw <2 x i32> <i32 0, i32 0>, %x
|
|
58 %sdiv = sdiv <2 x i32> %neg, %y
|
|
59 ret <2 x i32> %sdiv
|
|
60 }
|
|
61
|
|
62 define i32 @test_sdiv_canonicalize_multiple_uses(i32 %x, i32 %y) {
|
|
63 ; CHECK-LABEL: @test_sdiv_canonicalize_multiple_uses(
|
|
64 ; CHECK-NEXT: [[NEG:%.*]] = sub nsw i32 0, [[X:%.*]]
|
|
65 ; CHECK-NEXT: [[SDIV:%.*]] = sdiv i32 [[NEG]], [[Y:%.*]]
|
|
66 ; CHECK-NEXT: [[SDIV2:%.*]] = sdiv i32 [[SDIV]], [[NEG]]
|
|
67 ; CHECK-NEXT: ret i32 [[SDIV2]]
|
|
68 ;
|
|
69 %neg = sub nsw i32 0, %x
|
|
70 %sdiv = sdiv i32 %neg, %y
|
|
71 %sdiv2 = sdiv i32 %sdiv, %neg
|
|
72 ret i32 %sdiv2
|
|
73 }
|
|
74
|
|
75 ; There is combination: -(X/CE) -> (X/-CE).
|
|
76 ; If combines (X/-CE) to -(X/CE), make sure don't combine them endless.
|
|
77
|
|
78 @X = global i32 5
|
|
79
|
|
80 define i64 @test_sdiv_canonicalize_constexpr(i64 %L1) {
|
|
81 ; currently opt folds (sub nsw i64 0, constexpr) -> (sub i64, 0, constexpr).
|
|
82 ; sdiv canonicalize requires a nsw sub.
|
|
83 ; CHECK-LABEL: @test_sdiv_canonicalize_constexpr(
|
|
84 ; CHECK-NEXT: [[B4:%.*]] = sdiv i64 [[L1:%.*]], sub (i64 0, i64 ptrtoint (i32* @X to i64))
|
|
85 ; CHECK-NEXT: ret i64 [[B4]]
|
|
86 ;
|
|
87 %v1 = ptrtoint i32* @X to i64
|
|
88 %B8 = sub nsw i64 0, %v1
|
|
89 %B4 = sdiv i64 %L1, %B8
|
|
90 ret i64 %B4
|
|
91 }
|