1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instsimplify -S | FileCheck %s
4 define i32 @negate_nuw(i32 %x) {
5 ; CHECK-LABEL: @negate_nuw(
6 ; CHECK-NEXT: ret i32 0
8 %neg = sub nuw i32 0, %x
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
16 %neg = sub nuw <2 x i32> zeroinitializer, %x
20 define <2 x i32> @negate_nuw_vec_poison_elt(<2 x i32> %x) {
21 ; CHECK-LABEL: @negate_nuw_vec_poison_elt(
22 ; CHECK-NEXT: ret <2 x i32> zeroinitializer
24 %neg = sub nuw <2 x i32> <i32 0, i32 poison>, %x
28 define i8 @negate_zero_or_minsigned_nsw(i8 %x) {
29 ; CHECK-LABEL: @negate_zero_or_minsigned_nsw(
30 ; CHECK-NEXT: ret i8 0
32 %signbit = and i8 %x, 128
33 %neg = sub nsw i8 0, %signbit
37 define <2 x i8> @negate_zero_or_minsigned_nsw_vec(<2 x i8> %x) {
38 ; CHECK-LABEL: @negate_zero_or_minsigned_nsw_vec(
39 ; CHECK-NEXT: ret <2 x i8> zeroinitializer
41 %signbit = shl <2 x i8> %x, <i8 7, i8 7>
42 %neg = sub nsw <2 x i8> zeroinitializer, %signbit
46 define <2 x i8> @negate_zero_or_minsigned_nsw_vec_poison_elt(<2 x i8> %x) {
47 ; CHECK-LABEL: @negate_zero_or_minsigned_nsw_vec_poison_elt(
48 ; CHECK-NEXT: ret <2 x i8> zeroinitializer
50 %signbit = shl <2 x i8> %x, <i8 7, i8 7>
51 %neg = sub nsw <2 x i8> <i8 poison, i8 0>, %signbit
55 define i8 @negate_zero_or_minsigned(i8 %x) {
56 ; CHECK-LABEL: @negate_zero_or_minsigned(
57 ; CHECK-NEXT: [[SIGNBIT:%.*]] = shl i8 [[X:%.*]], 7
58 ; CHECK-NEXT: ret i8 [[SIGNBIT]]
60 %signbit = shl i8 %x, 7
61 %neg = sub i8 0, %signbit
65 define <2 x i8> @negate_zero_or_minsigned_vec(<2 x i8> %x) {
66 ; CHECK-LABEL: @negate_zero_or_minsigned_vec(
67 ; CHECK-NEXT: [[SIGNBIT:%.*]] = and <2 x i8> [[X:%.*]], <i8 -128, i8 -128>
68 ; CHECK-NEXT: ret <2 x i8> [[SIGNBIT]]
70 %signbit = and <2 x i8> %x, <i8 128, i8 128>
71 %neg = sub <2 x i8> zeroinitializer, %signbit