Sanjay Patel | 14eeb5a | 2018-07-11 16:52:18 +0000 | [diff] [blame^] | 1 | ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py |
| 2 | ; RUN: opt < %s -instsimplify -S | FileCheck %s |
| 3 | |
| 4 | define 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 | |
| 13 | define 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 | |
| 22 | define <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 | |
| 31 | define 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 | |
| 44 | define <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 | |