Sanjay Patel | cf26c27 | 2016-10-19 18:42:12 +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 @negate_nuw(i32 %x) { |
| 5 | ; CHECK-LABEL: @negate_nuw( |
| 6 | ; CHECK-NEXT: ret i32 0 |
| 7 | ; |
| 8 | %neg = sub nuw i32 0, %x |
| 9 | ret i32 %neg |
| 10 | } |
| 11 | |
| 12 | define <2 x i32> @negate_nuw_vec(<2 x i32> %x) { |
| 13 | ; CHECK-LABEL: @negate_nuw_vec( |
| 14 | ; CHECK-NEXT: ret <2 x i32> zeroinitializer |
| 15 | ; |
| 16 | %neg = sub nuw <2 x i32> zeroinitializer, %x |
| 17 | ret <2 x i32> %neg |
| 18 | } |
| 19 | |
| 20 | define i8 @negate_zero_or_minsigned_nsw(i8 %x) { |
| 21 | ; CHECK-LABEL: @negate_zero_or_minsigned_nsw( |
Sanjay Patel | efd8885 | 2016-10-19 21:23:45 +0000 | [diff] [blame] | 22 | ; CHECK-NEXT: ret i8 0 |
Sanjay Patel | cf26c27 | 2016-10-19 18:42:12 +0000 | [diff] [blame] | 23 | ; |
| 24 | %signbit = and i8 %x, 128 |
| 25 | %neg = sub nsw i8 0, %signbit |
| 26 | ret i8 %neg |
| 27 | } |
| 28 | |
| 29 | define <2 x i8> @negate_zero_or_minsigned_nsw_vec(<2 x i8> %x) { |
| 30 | ; CHECK-LABEL: @negate_zero_or_minsigned_nsw_vec( |
Sanjay Patel | efd8885 | 2016-10-19 21:23:45 +0000 | [diff] [blame] | 31 | ; CHECK-NEXT: ret <2 x i8> zeroinitializer |
Sanjay Patel | cf26c27 | 2016-10-19 18:42:12 +0000 | [diff] [blame] | 32 | ; |
| 33 | %signbit = shl <2 x i8> %x, <i8 7, i8 7> |
| 34 | %neg = sub nsw <2 x i8> zeroinitializer, %signbit |
| 35 | ret <2 x i8> %neg |
| 36 | } |
| 37 | |
| 38 | define i8 @negate_zero_or_minsigned(i8 %x) { |
| 39 | ; CHECK-LABEL: @negate_zero_or_minsigned( |
| 40 | ; CHECK-NEXT: [[SIGNBIT:%.*]] = shl i8 %x, 7 |
Sanjay Patel | efd8885 | 2016-10-19 21:23:45 +0000 | [diff] [blame] | 41 | ; CHECK-NEXT: ret i8 [[SIGNBIT]] |
Sanjay Patel | cf26c27 | 2016-10-19 18:42:12 +0000 | [diff] [blame] | 42 | ; |
| 43 | %signbit = shl i8 %x, 7 |
| 44 | %neg = sub i8 0, %signbit |
| 45 | ret i8 %neg |
| 46 | } |
| 47 | |
| 48 | define <2 x i8> @negate_zero_or_minsigned_vec(<2 x i8> %x) { |
| 49 | ; CHECK-LABEL: @negate_zero_or_minsigned_vec( |
| 50 | ; CHECK-NEXT: [[SIGNBIT:%.*]] = and <2 x i8> %x, <i8 -128, i8 -128> |
Sanjay Patel | efd8885 | 2016-10-19 21:23:45 +0000 | [diff] [blame] | 51 | ; CHECK-NEXT: ret <2 x i8> [[SIGNBIT]] |
Sanjay Patel | cf26c27 | 2016-10-19 18:42:12 +0000 | [diff] [blame] | 52 | ; |
| 53 | %signbit = and <2 x i8> %x, <i8 128, i8 128> |
| 54 | %neg = sub <2 x i8> zeroinitializer, %signbit |
| 55 | ret <2 x i8> %neg |
| 56 | } |
| 57 | |