64 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt < %s -passes=instcombine -S | FileCheck %s3 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, %x11 %srem = srem i32 %neg, %y12 ret i32 %srem13}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:%.*]], 319; 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, 324 %neg = sub nsw i32 0, %x25 %srem = srem i32 %y, %neg26 ret i32 %srem27}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, %x36 %srem = srem i32 %neg, %y37 ret i32 %srem38}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>, %x47 %srem = srem <2 x i32> %neg, %y48 ret <2 x i32> %srem49}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, %x59 %srem = srem i32 %neg, %y60 %srem2 = srem i32 %srem, %neg61 ret i32 %srem262}63 64