blob: 17eb52d3527d5dbd34fd03272e904f105ffa6b3c [file] [log] [blame]
Sanjay Patelcf26c272016-10-19 18:42:12 +00001; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s -instsimplify -S | FileCheck %s
3
4define 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
12define <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
20define i8 @negate_zero_or_minsigned_nsw(i8 %x) {
21; CHECK-LABEL: @negate_zero_or_minsigned_nsw(
Sanjay Patelefd88852016-10-19 21:23:45 +000022; CHECK-NEXT: ret i8 0
Sanjay Patelcf26c272016-10-19 18:42:12 +000023;
24 %signbit = and i8 %x, 128
25 %neg = sub nsw i8 0, %signbit
26 ret i8 %neg
27}
28
29define <2 x i8> @negate_zero_or_minsigned_nsw_vec(<2 x i8> %x) {
30; CHECK-LABEL: @negate_zero_or_minsigned_nsw_vec(
Sanjay Patelefd88852016-10-19 21:23:45 +000031; CHECK-NEXT: ret <2 x i8> zeroinitializer
Sanjay Patelcf26c272016-10-19 18:42:12 +000032;
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
38define i8 @negate_zero_or_minsigned(i8 %x) {
39; CHECK-LABEL: @negate_zero_or_minsigned(
40; CHECK-NEXT: [[SIGNBIT:%.*]] = shl i8 %x, 7
Sanjay Patelefd88852016-10-19 21:23:45 +000041; CHECK-NEXT: ret i8 [[SIGNBIT]]
Sanjay Patelcf26c272016-10-19 18:42:12 +000042;
43 %signbit = shl i8 %x, 7
44 %neg = sub i8 0, %signbit
45 ret i8 %neg
46}
47
48define <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 Patelefd88852016-10-19 21:23:45 +000051; CHECK-NEXT: ret <2 x i8> [[SIGNBIT]]
Sanjay Patelcf26c272016-10-19 18:42:12 +000052;
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