1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
4 define 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]]
10 %neg = sub nsw i32 0, %x
11 %srem = srem i32 %neg, %y
15 ; (X srem -Y) is not equal to -(X srem Y), don't canonicalize.
16 define 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]]
24 %neg = sub nsw i32 0, %x
25 %srem = srem i32 %y, %neg
29 define 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]]
36 %srem = srem i32 %neg, %y
40 define <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]]
46 %neg = sub nsw <2 x i32> <i32 0, i32 0>, %x
47 %srem = srem <2 x i32> %neg, %y
51 define 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]]
58 %neg = sub nsw i32 0, %x
59 %srem = srem i32 %neg, %y
60 %srem2 = srem i32 %srem, %neg