blob: d32b2551ab12d6dbc52ea1157f7e648dd0bde1dc [file] [log] [blame]
Sanjay Patel14eeb5a2018-07-11 16:52:18 +00001; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s -instsimplify -S | FileCheck %s
3
4define i32 @common_sub_operand(i32 %X, i32 %Y) {
5; CHECK-LABEL: @common_sub_operand(
6; CHECK-NEXT: ret i32 [[X:%.*]]
7;
8 %Z = sub i32 %X, %Y
9 %Q = add i32 %Z, %Y
10 ret i32 %Q
11}
12
13define i32 @negated_operand(i32 %x) {
14; CHECK-LABEL: @negated_operand(
15; CHECK-NEXT: ret i32 0
16;
17 %negx = sub i32 0, %x
18 %r = add i32 %negx, %x
19 ret i32 %r
20}
21
22define <2 x i32> @negated_operand_commute_vec(<2 x i32> %x) {
23; CHECK-LABEL: @negated_operand_commute_vec(
24; CHECK-NEXT: ret <2 x i32> zeroinitializer
25;
26 %negx = sub <2 x i32> zeroinitializer, %x
27 %r = add <2 x i32> %x, %negx
28 ret <2 x i32> %r
29}
30
31define i8 @knownnegation(i8 %x, i8 %y) {
32; CHECK-LABEL: @knownnegation(
33; CHECK-NEXT: [[XY:%.*]] = sub i8 [[X:%.*]], [[Y:%.*]]
34; CHECK-NEXT: [[YX:%.*]] = sub i8 [[Y]], [[X]]
35; CHECK-NEXT: [[R:%.*]] = add i8 [[XY]], [[YX]]
36; CHECK-NEXT: ret i8 [[R]]
37;
38 %xy = sub i8 %x, %y
39 %yx = sub i8 %y, %x
40 %r = add i8 %xy, %yx
41 ret i8 %r
42}
43
44define <2 x i8> @knownnegation_commute_vec(<2 x i8> %x, <2 x i8> %y) {
45; CHECK-LABEL: @knownnegation_commute_vec(
46; CHECK-NEXT: [[XY:%.*]] = sub <2 x i8> [[X:%.*]], [[Y:%.*]]
47; CHECK-NEXT: [[YX:%.*]] = sub <2 x i8> [[Y]], [[X]]
48; CHECK-NEXT: [[R:%.*]] = add <2 x i8> [[YX]], [[XY]]
49; CHECK-NEXT: ret <2 x i8> [[R]]
50;
51 %xy = sub <2 x i8> %x, %y
52 %yx = sub <2 x i8> %y, %x
53 %r = add <2 x i8> %yx, %xy
54 ret <2 x i8> %r
55}
56
57