• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s -instcombine -S | FileCheck %s
3
4define i32 @test_srem_canonicalize_op0(i32 %x, i32 %y) {
5; CHECK-LABEL: @test_srem_canonicalize_op0(
6; CHECK-NEXT:    [[TMP1:%.*]] = srem i32 [[X:%.*]], [[Y:%.*]]
7; CHECK-NEXT:    [[SREM:%.*]] = sub nsw i32 0, [[TMP1]]
8; CHECK-NEXT:    ret i32 [[SREM]]
9;
10  %neg = sub nsw i32 0, %x
11  %srem = srem i32 %neg, %y
12  ret i32 %srem
13}
14
15; (X srem -Y) is not equal to -(X srem Y), don't canonicalize.
16define i32 @test_srem_canonicalize_op1(i32 %x, i32 %z) {
17; CHECK-LABEL: @test_srem_canonicalize_op1(
18; CHECK-NEXT:    [[Y:%.*]] = mul i32 [[Z:%.*]], 3
19; CHECK-NEXT:    [[NEG:%.*]] = sub nsw i32 0, [[X:%.*]]
20; CHECK-NEXT:    [[SREM:%.*]] = srem i32 [[Y]], [[NEG]]
21; CHECK-NEXT:    ret i32 [[SREM]]
22;
23  %y = mul i32 %z, 3
24  %neg = sub nsw i32 0, %x
25  %srem = srem i32 %y, %neg
26  ret i32 %srem
27}
28
29define i32 @test_srem_canonicalize_nonsw(i32 %x, i32 %y) {
30; CHECK-LABEL: @test_srem_canonicalize_nonsw(
31; CHECK-NEXT:    [[NEG:%.*]] = sub i32 0, [[X:%.*]]
32; CHECK-NEXT:    [[SREM:%.*]] = srem i32 [[NEG]], [[Y:%.*]]
33; CHECK-NEXT:    ret i32 [[SREM]]
34;
35  %neg = sub i32 0, %x
36  %srem = srem i32 %neg, %y
37  ret i32 %srem
38}
39
40define <2 x i32> @test_srem_canonicalize_vec(<2 x i32> %x, <2 x i32> %y) {
41; CHECK-LABEL: @test_srem_canonicalize_vec(
42; CHECK-NEXT:    [[TMP1:%.*]] = srem <2 x i32> [[X:%.*]], [[Y:%.*]]
43; CHECK-NEXT:    [[SREM:%.*]] = sub nsw <2 x i32> zeroinitializer, [[TMP1]]
44; CHECK-NEXT:    ret <2 x i32> [[SREM]]
45;
46  %neg = sub nsw <2 x i32> <i32 0, i32 0>, %x
47  %srem = srem <2 x i32> %neg, %y
48  ret <2 x i32> %srem
49}
50
51define i32 @test_srem_canonicalize_multiple_uses(i32 %x, i32 %y) {
52; CHECK-LABEL: @test_srem_canonicalize_multiple_uses(
53; CHECK-NEXT:    [[NEG:%.*]] = sub nsw i32 0, [[X:%.*]]
54; CHECK-NEXT:    [[SREM:%.*]] = srem i32 [[NEG]], [[Y:%.*]]
55; CHECK-NEXT:    [[SREM2:%.*]] = srem i32 [[SREM]], [[NEG]]
56; CHECK-NEXT:    ret i32 [[SREM2]]
57;
58  %neg = sub nsw i32 0, %x
59  %srem = srem i32 %neg, %y
60  %srem2 = srem i32 %srem, %neg
61  ret i32 %srem2
62}
63
64