1240aff80SAlex Richardson; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2e5b87727SSanjay Patel; Example input for update_test_checks (taken from test/Transforms/InstSimplify/add.ll)
3*40760060SBjorn Pettersson; RUN: opt < %s -passes=instsimplify -S | FileCheck %s
4240aff80SAlex Richardson
5240aff80SAlex Richardsondefine i32 @common_sub_operand(i32 %X, i32 %Y) {
6240aff80SAlex Richardson; CHECK-LABEL: @common_sub_operand(
7240aff80SAlex Richardson; CHECK-NEXT:    ret i32 [[X:%.*]]
8240aff80SAlex Richardson;
9240aff80SAlex Richardson  %Z = sub i32 %X, %Y
10240aff80SAlex Richardson  %Q = add i32 %Z, %Y
11240aff80SAlex Richardson  ret i32 %Q
12240aff80SAlex Richardson}
13240aff80SAlex Richardson
14240aff80SAlex Richardsondefine i32 @negated_operand(i32 %x) {
15240aff80SAlex Richardson; CHECK-LABEL: @negated_operand(
16240aff80SAlex Richardson; CHECK-NEXT:    ret i32 0
17240aff80SAlex Richardson;
18240aff80SAlex Richardson  %negx = sub i32 0, %x
19240aff80SAlex Richardson  %r = add i32 %negx, %x
20240aff80SAlex Richardson  ret i32 %r
21240aff80SAlex Richardson}
22240aff80SAlex Richardson
23240aff80SAlex Richardsondefine <2 x i32> @negated_operand_commute_vec(<2 x i32> %x) {
24240aff80SAlex Richardson; CHECK-LABEL: @negated_operand_commute_vec(
25240aff80SAlex Richardson; CHECK-NEXT:    ret <2 x i32> zeroinitializer
26240aff80SAlex Richardson;
27240aff80SAlex Richardson  %negx = sub <2 x i32> zeroinitializer, %x
28240aff80SAlex Richardson  %r = add <2 x i32> %x, %negx
29240aff80SAlex Richardson  ret <2 x i32> %r
30240aff80SAlex Richardson}
31240aff80SAlex Richardson
32240aff80SAlex Richardsondefine i8 @knownnegation(i8 %x, i8 %y) {
33240aff80SAlex Richardson; CHECK-LABEL: @knownnegation(
34240aff80SAlex Richardson; CHECK-NEXT:    ret i8 0
35240aff80SAlex Richardson;
36240aff80SAlex Richardson  %xy = sub i8 %x, %y
37240aff80SAlex Richardson  %yx = sub i8 %y, %x
38240aff80SAlex Richardson  %r = add i8 %xy, %yx
39240aff80SAlex Richardson  ret i8 %r
40240aff80SAlex Richardson}
41240aff80SAlex Richardson
42240aff80SAlex Richardsondefine <2 x i8> @knownnegation_commute_vec(<2 x i8> %x, <2 x i8> %y) {
43240aff80SAlex Richardson; CHECK-LABEL: @knownnegation_commute_vec(
44240aff80SAlex Richardson; CHECK-NEXT:    ret <2 x i8> zeroinitializer
45240aff80SAlex Richardson;
46240aff80SAlex Richardson  %xy = sub <2 x i8> %x, %y
47240aff80SAlex Richardson  %yx = sub <2 x i8> %y, %x
48240aff80SAlex Richardson  %r = add <2 x i8> %yx, %xy
49240aff80SAlex Richardson  ret <2 x i8> %r
50240aff80SAlex Richardson}
51e5b87727SSanjay Patel
52e5b87727SSanjay Pateldefine i32 @nameless_value(i32 %X) {
53e5b87727SSanjay Patel; CHECK-LABEL: @nameless_value(
54e5b87727SSanjay Patel; CHECK-NEXT:    [[TMP1:%.*]] = sub i32 42, [[X:%.*]]
55e5b87727SSanjay Patel; CHECK-NEXT:    ret i32 [[TMP1]]
56e5b87727SSanjay Patel;
57e5b87727SSanjay Patel  %1 = sub i32 42, %X
58e5b87727SSanjay Patel  ret i32 %1
59e5b87727SSanjay Patel}
60