|
| 1 | +; RUN: opt < %s -instsimplify -S | FileCheck %s |
| 2 | + |
| 3 | +define i32 @negated_operand(i32 %x) { |
| 4 | +; CHECK-LABEL: @negated_operand( |
| 5 | +; CHECK-NEXT: [[NEGX:%.*]] = sub i32 0, [[X:%.*]] |
| 6 | +; CHECK-NEXT: [[REM:%.*]] = srem i32 [[NEGX]], [[X]] |
| 7 | +; CHECK-NEXT: ret i32 [[REM]] |
| 8 | +; |
| 9 | + %negx = sub i32 0, %x |
| 10 | + %rem = srem i32 %negx, %x |
| 11 | + ret i32 %rem |
| 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: [[REM:%.*]] = srem <2 x i32> [[NEGX]], [[X]] |
| 18 | +; CHECK-NEXT: ret <2 x i32> [[REM]] |
| 19 | +; |
| 20 | + %negx = sub nsw <2 x i32> zeroinitializer, %x |
| 21 | + %rem = srem <2 x i32> %negx, %x |
| 22 | + ret <2 x i32> %rem |
| 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: [[REM:%.*]] = srem i32 [[XY]], [[YX]] |
| 30 | +; CHECK-NEXT: ret i32 [[REM]] |
| 31 | +; |
| 32 | + %xy = sub nsw i32 %x, %y |
| 33 | + %yx = sub nsw i32 %y, %x |
| 34 | + %rem = srem i32 %xy, %yx |
| 35 | + ret i32 %rem |
| 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: [[REM:%.*]] = srem <2 x i32> [[XY]], [[YX]] |
| 43 | +; CHECK-NEXT: ret <2 x i32> [[REM]] |
| 44 | +; |
| 45 | + %xy = sub nsw <2 x i32> %x, %y |
| 46 | + %yx = sub nsw <2 x i32> %y, %x |
| 47 | + %rem = srem <2 x i32> %xy, %yx |
| 48 | + ret <2 x i32> %rem |
| 49 | +} |
0 commit comments