99 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt -S < %s -passes=instcombine | FileCheck %s3 4; Fold5; (X & C) - X6; to7; - (X & ~C)8;9; This allows us to possibly hoist said negation further out,10; and decreases use count of X.11 12; https://bugs.llvm.org/show_bug.cgi?id=4442713 14; Base tests15 16define i8 @t0(i8 %x) {17; CHECK-LABEL: @t0(18; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[X:%.*]], -4319; CHECK-NEXT: [[NEGBIAS:%.*]] = sub i8 0, [[TMP1]]20; CHECK-NEXT: ret i8 [[NEGBIAS]]21;22 %unbiasedx = and i8 %x, 4223 %negbias = sub i8 %unbiasedx, %x24 ret i8 %negbias25}26 27define <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]]32;33 %unbiasedx = and <2 x i8> %x, <i8 42, i8 42>34 %negbias = sub <2 x i8> %unbiasedx, %x35 ret <2 x i8> %negbias36}37 38define <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]]43;44 %unbiasedx = and <2 x i8> %x, <i8 42, i8 undef>45 %negbias = sub <2 x i8> %unbiasedx, %x46 ret <2 x i8> %negbias47}48 49define <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]]54;55 %unbiasedx = and <2 x i8> %x, <i8 42, i8 44>56 %negbias = sub <2 x i8> %unbiasedx, %x57 ret <2 x i8> %negbias58}59 60; Extra uses always prevent fold61 62declare void @use8(i8)63 64define i8 @n4_extrause(i8 %x) {65; CHECK-LABEL: @n4_extrause(66; CHECK-NEXT: [[UNBIASEDX:%.*]] = and i8 [[X:%.*]], 4267; CHECK-NEXT: call void @use8(i8 [[UNBIASEDX]])68; CHECK-NEXT: [[NEGBIAS:%.*]] = sub i8 [[UNBIASEDX]], [[X]]69; CHECK-NEXT: ret i8 [[NEGBIAS]]70;71 %unbiasedx = and i8 %x, 4272 call void @use8(i8 %unbiasedx)73 %negbias = sub i8 %unbiasedx, %x74 ret i8 %negbias75}76 77; Negative tests78 79define i8 @n5(i8 %x) {80; CHECK-LABEL: @n5(81; CHECK-NEXT: [[NEGBIAS:%.*]] = and i8 [[X:%.*]], -4382; CHECK-NEXT: ret i8 [[NEGBIAS]]83;84 %unbiasedx = and i8 %x, 4285 %negbias = sub i8 %x, %unbiasedx ; wrong order86 ret i8 %negbias87}88 89define i8 @n6(i8 %x0, i8 %x1) {90; CHECK-LABEL: @n6(91; CHECK-NEXT: [[UNBIASEDX:%.*]] = and i8 [[X1:%.*]], 4292; CHECK-NEXT: [[NEGBIAS:%.*]] = sub i8 [[UNBIASEDX]], [[X0:%.*]]93; CHECK-NEXT: ret i8 [[NEGBIAS]]94;95 %unbiasedx = and i8 %x1, 42 ; not %x096 %negbias = sub i8 %unbiasedx, %x0 ; not %x197 ret i8 %negbias98}99