xref: /llvm-project/llvm/test/Transforms/InstSimplify/add.ll (revision b280ee1dd7e9b36ae7aaa3953556e4b7a7f31a29)
1cee313d2SEric Christopher; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2*b280ee1dSBjorn Pettersson; RUN: opt < %s -passes=instsimplify -S | FileCheck %s
3cee313d2SEric Christopher
4cee313d2SEric Christopherdefine i32 @common_sub_operand(i32 %X, i32 %Y) {
5cee313d2SEric Christopher; CHECK-LABEL: @common_sub_operand(
6cee313d2SEric Christopher; CHECK-NEXT:    ret i32 [[X:%.*]]
7cee313d2SEric Christopher;
8cee313d2SEric Christopher  %Z = sub i32 %X, %Y
9cee313d2SEric Christopher  %Q = add i32 %Z, %Y
10cee313d2SEric Christopher  ret i32 %Q
11cee313d2SEric Christopher}
12cee313d2SEric Christopher
13cee313d2SEric Christopherdefine i32 @negated_operand(i32 %x) {
14cee313d2SEric Christopher; CHECK-LABEL: @negated_operand(
15cee313d2SEric Christopher; CHECK-NEXT:    ret i32 0
16cee313d2SEric Christopher;
17cee313d2SEric Christopher  %negx = sub i32 0, %x
18cee313d2SEric Christopher  %r = add i32 %negx, %x
19cee313d2SEric Christopher  ret i32 %r
20cee313d2SEric Christopher}
21cee313d2SEric Christopher
22cee313d2SEric Christopherdefine <2 x i32> @negated_operand_commute_vec(<2 x i32> %x) {
23cee313d2SEric Christopher; CHECK-LABEL: @negated_operand_commute_vec(
24cee313d2SEric Christopher; CHECK-NEXT:    ret <2 x i32> zeroinitializer
25cee313d2SEric Christopher;
26cee313d2SEric Christopher  %negx = sub <2 x i32> zeroinitializer, %x
27cee313d2SEric Christopher  %r = add <2 x i32> %x, %negx
28cee313d2SEric Christopher  ret <2 x i32> %r
29cee313d2SEric Christopher}
30cee313d2SEric Christopher
31cee313d2SEric Christopherdefine i8 @knownnegation(i8 %x, i8 %y) {
32cee313d2SEric Christopher; CHECK-LABEL: @knownnegation(
33cee313d2SEric Christopher; CHECK-NEXT:    ret i8 0
34cee313d2SEric Christopher;
35cee313d2SEric Christopher  %xy = sub i8 %x, %y
36cee313d2SEric Christopher  %yx = sub i8 %y, %x
37cee313d2SEric Christopher  %r = add i8 %xy, %yx
38cee313d2SEric Christopher  ret i8 %r
39cee313d2SEric Christopher}
40cee313d2SEric Christopher
41cee313d2SEric Christopherdefine <2 x i8> @knownnegation_commute_vec(<2 x i8> %x, <2 x i8> %y) {
42cee313d2SEric Christopher; CHECK-LABEL: @knownnegation_commute_vec(
43cee313d2SEric Christopher; CHECK-NEXT:    ret <2 x i8> zeroinitializer
44cee313d2SEric Christopher;
45cee313d2SEric Christopher  %xy = sub <2 x i8> %x, %y
46cee313d2SEric Christopher  %yx = sub <2 x i8> %y, %x
47cee313d2SEric Christopher  %r = add <2 x i8> %yx, %xy
48cee313d2SEric Christopher  ret <2 x i8> %r
49cee313d2SEric Christopher}
50cee313d2SEric Christopher
51864dda5fSJuneyoung Leedefine i32 @poison(i32 %x) {
52864dda5fSJuneyoung Lee; CHECK-LABEL: @poison(
53864dda5fSJuneyoung Lee; CHECK-NEXT:    ret i32 poison
54864dda5fSJuneyoung Lee;
55864dda5fSJuneyoung Lee  %y = add i32 %x, poison
56864dda5fSJuneyoung Lee  ret i32 %y
57864dda5fSJuneyoung Lee}
58