1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S < %s -passes=instcombine | FileCheck %s
9 ; This allows us to possibly hoist said negation further out,
10 ; and decreases use count of X.
12 ; https://bugs.llvm.org/show_bug.cgi?id=44427
16 define i8 @t0(i8 %x) {
18 ; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[X:%.*]], -43
19 ; CHECK-NEXT: [[NEGBIAS:%.*]] = sub i8 0, [[TMP1]]
20 ; CHECK-NEXT: ret i8 [[NEGBIAS]]
22 %unbiasedx = and i8 %x, 42
23 %negbias = sub i8 %unbiasedx, %x
27 define <2 x i8> @t1_vec(<2 x i8> %x) {
28 ; CHECK-LABEL: @t1_vec(
29 ; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i8> [[X:%.*]], splat (i8 -43)
30 ; CHECK-NEXT: [[NEGBIAS:%.*]] = sub <2 x i8> zeroinitializer, [[TMP1]]
31 ; CHECK-NEXT: ret <2 x i8> [[NEGBIAS]]
33 %unbiasedx = and <2 x i8> %x, <i8 42, i8 42>
34 %negbias = sub <2 x i8> %unbiasedx, %x
38 define <2 x i8> @t2_vec_undef(<2 x i8> %x) {
39 ; CHECK-LABEL: @t2_vec_undef(
40 ; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i8> [[X:%.*]], <i8 -43, i8 undef>
41 ; CHECK-NEXT: [[NEGBIAS:%.*]] = sub <2 x i8> zeroinitializer, [[TMP1]]
42 ; CHECK-NEXT: ret <2 x i8> [[NEGBIAS]]
44 %unbiasedx = and <2 x i8> %x, <i8 42, i8 undef>
45 %negbias = sub <2 x i8> %unbiasedx, %x
49 define <2 x i8> @t3_vec_nonsplat(<2 x i8> %x) {
50 ; CHECK-LABEL: @t3_vec_nonsplat(
51 ; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i8> [[X:%.*]], <i8 -43, i8 -45>
52 ; CHECK-NEXT: [[NEGBIAS:%.*]] = sub <2 x i8> zeroinitializer, [[TMP1]]
53 ; CHECK-NEXT: ret <2 x i8> [[NEGBIAS]]
55 %unbiasedx = and <2 x i8> %x, <i8 42, i8 44>
56 %negbias = sub <2 x i8> %unbiasedx, %x
60 ; Extra uses always prevent fold
62 declare void @use8(i8)
64 define i8 @n4_extrause(i8 %x) {
65 ; CHECK-LABEL: @n4_extrause(
66 ; CHECK-NEXT: [[UNBIASEDX:%.*]] = and i8 [[X:%.*]], 42
67 ; CHECK-NEXT: call void @use8(i8 [[UNBIASEDX]])
68 ; CHECK-NEXT: [[NEGBIAS:%.*]] = sub i8 [[UNBIASEDX]], [[X]]
69 ; CHECK-NEXT: ret i8 [[NEGBIAS]]
71 %unbiasedx = and i8 %x, 42
72 call void @use8(i8 %unbiasedx)
73 %negbias = sub i8 %unbiasedx, %x
79 define i8 @n5(i8 %x) {
81 ; CHECK-NEXT: [[NEGBIAS:%.*]] = and i8 [[X:%.*]], -43
82 ; CHECK-NEXT: ret i8 [[NEGBIAS]]
84 %unbiasedx = and i8 %x, 42
85 %negbias = sub i8 %x, %unbiasedx ; wrong order
89 define i8 @n6(i8 %x0, i8 %x1) {
91 ; CHECK-NEXT: [[UNBIASEDX:%.*]] = and i8 [[X1:%.*]], 42
92 ; CHECK-NEXT: [[NEGBIAS:%.*]] = sub i8 [[UNBIASEDX]], [[X0:%.*]]
93 ; CHECK-NEXT: ret i8 [[NEGBIAS]]
95 %unbiasedx = and i8 %x1, 42 ; not %x0
96 %negbias = sub i8 %unbiasedx, %x0 ; not %x1