1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instsimplify -S | FileCheck %s
4 define i32 @negated_operand(i32 %x) {
5 ; CHECK-LABEL: @negated_operand(
6 ; CHECK-NEXT: ret i32 0
9 %rem = srem i32 %negx, %x
13 define <2 x i32> @negated_operand_commute_vec(<2 x i32> %x) {
14 ; CHECK-LABEL: @negated_operand_commute_vec(
15 ; CHECK-NEXT: ret <2 x i32> zeroinitializer
17 %negx = sub <2 x i32> zeroinitializer, %x
18 %rem = srem <2 x i32> %negx, %x
22 define i32 @knownnegation(i32 %x, i32 %y) {
23 ; CHECK-LABEL: @knownnegation(
24 ; CHECK-NEXT: ret i32 0
28 %rem = srem i32 %xy, %yx
32 define <2 x i32> @knownnegation_commute_vec(<2 x i32> %x, <2 x i32> %y) {
33 ; CHECK-LABEL: @knownnegation_commute_vec(
34 ; CHECK-NEXT: ret <2 x i32> zeroinitializer
36 %xy = sub <2 x i32> %x, %y
37 %yx = sub <2 x i32> %y, %x
38 %rem = srem <2 x i32> %xy, %yx
42 define <3 x i32> @negated_operand_vec_undef(<3 x i32> %x) {
43 ; CHECK-LABEL: @negated_operand_vec_undef(
44 ; CHECK-NEXT: ret <3 x i32> zeroinitializer
46 %negx = sub <3 x i32> <i32 0, i32 undef, i32 0>, %x
47 %rem = srem <3 x i32> %negx, %x
51 define <2 x i32> @negated_operand_vec_nonsplat(<2 x i32> %x) {
52 ; CHECK-LABEL: @negated_operand_vec_nonsplat(
53 ; CHECK-NEXT: [[NEGX:%.*]] = sub <2 x i32> <i32 0, i32 1>, [[X:%.*]]
54 ; CHECK-NEXT: [[REM:%.*]] = srem <2 x i32> [[NEGX]], [[X]]
55 ; CHECK-NEXT: ret <2 x i32> [[REM]]
57 %negx = sub <2 x i32> <i32 0, i32 1>, %x ; not 0, don't fold
58 %rem = srem <2 x i32> %negx, %x
62 define i32 @negated_operand_commute(i32 %x) {
63 ; CHECK-LABEL: @negated_operand_commute(
64 ; CHECK-NEXT: ret i32 0
67 %rem = srem i32 %x, %negx