Chen Zheng | 1ff4931 | 2018-07-16 15:06:42 +0000 | [diff] [blame^] | 1 | ; RUN: opt < %s -instcombine -S | FileCheck %s |
| 2 | |
| 3 | define i32 @negated_operand(i32 %x) { |
| 4 | ; CHECK-LABEL: @negated_operand( |
| 5 | ; CHECK-NEXT: [[NEGX:%.*]] = sub nsw i32 0, [[X:%.*]] |
| 6 | ; CHECK-NEXT: [[DIV:%.*]] = sdiv i32 [[NEGX]], [[X]] |
| 7 | ; CHECK-NEXT: ret i32 [[DIV]] |
| 8 | ; |
| 9 | %negx = sub nsw i32 0, %x |
| 10 | %div = sdiv i32 %negx, %x |
| 11 | ret i32 %div |
| 12 | } |
| 13 | |
| 14 | define <2 x i32> @negated_operand_commute_vec(<2 x i32> %x) { |
| 15 | ; CHECK-LABEL: @negated_operand_commute_vec( |
| 16 | ; CHECK-NEXT: [[NEGX:%.*]] = sub nsw <2 x i32> zeroinitializer, [[X:%.*]] |
| 17 | ; CHECK-NEXT: [[DIV:%.*]] = sdiv <2 x i32> [[NEGX]], [[X]] |
| 18 | ; CHECK-NEXT: ret <2 x i32> [[DIV]] |
| 19 | ; |
| 20 | %negx = sub nsw <2 x i32> zeroinitializer, %x |
| 21 | %div = sdiv <2 x i32> %negx, %x |
| 22 | ret <2 x i32> %div |
| 23 | } |
| 24 | |
| 25 | define i32 @knownnegation(i32 %x, i32 %y) { |
| 26 | ; CHECK-LABEL: @knownnegation( |
| 27 | ; CHECK-NEXT: [[XY:%.*]] = sub nsw i32 [[X:%.*]], [[Y:%.*]] |
| 28 | ; CHECK-NEXT: [[YX:%.*]] = sub nsw i32 [[Y]], [[X]] |
| 29 | ; CHECK-NEXT: [[DIV:%.*]] = sdiv i32 [[XY]], [[YX]] |
| 30 | ; CHECK-NEXT: ret i32 [[DIV]] |
| 31 | ; |
| 32 | %xy = sub nsw i32 %x, %y |
| 33 | %yx = sub nsw i32 %y, %x |
| 34 | %div = sdiv i32 %xy, %yx |
| 35 | ret i32 %div |
| 36 | } |
| 37 | |
| 38 | define <2 x i32> @knownnegation_commute_vec(<2 x i32> %x, <2 x i32> %y) { |
| 39 | ; CHECK-LABEL: @knownnegation_commute_vec( |
| 40 | ; CHECK-NEXT: [[XY:%.*]] = sub nsw <2 x i32> [[X:%.*]], [[Y:%.*]] |
| 41 | ; CHECK-NEXT: [[YX:%.*]] = sub nsw <2 x i32> [[Y]], [[X]] |
| 42 | ; CHECK-NEXT: [[DIV:%.*]] = sdiv <2 x i32> [[XY]], [[YX]] |
| 43 | ; CHECK-NEXT: ret <2 x i32> [[DIV]] |
| 44 | ; |
| 45 | %xy = sub nsw <2 x i32> %x, %y |
| 46 | %yx = sub nsw <2 x i32> %y, %x |
| 47 | %div = sdiv <2 x i32> %xy, %yx |
| 48 | ret <2 x i32> %div |
| 49 | } |