69 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt < %s -passes=instcombine -S | FileCheck %s3 4; Transform5; (~x) a>> y6; into:7; ~(x a>> y)8 9declare void @use8(i8)10 11; Most basic positive test12define i8 @t0(i8 %x, i8 %y) {13; CHECK-LABEL: @t0(14; CHECK-NEXT: [[NOT_X_NOT:%.*]] = ashr i8 [[X:%.*]], [[Y:%.*]]15; CHECK-NEXT: [[ASHR:%.*]] = xor i8 [[NOT_X_NOT]], -116; CHECK-NEXT: ret i8 [[ASHR]]17;18 %not_x = xor i8 %x, -119 %ashr = ashr i8 %not_x, %y20 ret i8 %ashr21}22; 'exact'-ness isn't preserved!23define i8 @t1(i8 %x, i8 %y) {24; CHECK-LABEL: @t1(25; CHECK-NEXT: [[NOT_X_NOT:%.*]] = ashr i8 [[X:%.*]], [[Y:%.*]]26; CHECK-NEXT: [[ASHR:%.*]] = xor i8 [[NOT_X_NOT]], -127; CHECK-NEXT: ret i8 [[ASHR]]28;29 %not_x = xor i8 %x, -130 %ashr = ashr exact i8 %not_x, %y31 ret i8 %ashr32}33; Basic vector test34define <2 x i8> @t2_vec(<2 x i8> %x, <2 x i8> %y) {35; CHECK-LABEL: @t2_vec(36; CHECK-NEXT: [[NOT_X_NOT:%.*]] = ashr <2 x i8> [[X:%.*]], [[Y:%.*]]37; CHECK-NEXT: [[ASHR:%.*]] = xor <2 x i8> [[NOT_X_NOT]], splat (i8 -1)38; CHECK-NEXT: ret <2 x i8> [[ASHR]]39;40 %not_x = xor <2 x i8> %x, <i8 -1, i8 -1>41 %ashr = ashr <2 x i8> %not_x, %y42 ret <2 x i8> %ashr43}44; Note that we must sanitize poison elts of -1 constant to -1 or 0.45define <2 x i8> @t3_vec_poison(<2 x i8> %x, <2 x i8> %y) {46; CHECK-LABEL: @t3_vec_poison(47; CHECK-NEXT: [[NOT_X_NOT:%.*]] = ashr <2 x i8> [[X:%.*]], [[Y:%.*]]48; CHECK-NEXT: [[ASHR:%.*]] = xor <2 x i8> [[NOT_X_NOT]], splat (i8 -1)49; CHECK-NEXT: ret <2 x i8> [[ASHR]]50;51 %not_x = xor <2 x i8> %x, <i8 -1, i8 poison>52 %ashr = ashr <2 x i8> %not_x, %y53 ret <2 x i8> %ashr54}55 56; Extra use prevents the fold.57define i8 @n4(i8 %x, i8 %y) {58; CHECK-LABEL: @n4(59; CHECK-NEXT: [[NOT_X:%.*]] = xor i8 [[X:%.*]], -160; CHECK-NEXT: call void @use8(i8 [[NOT_X]])61; CHECK-NEXT: [[ASHR:%.*]] = ashr i8 [[NOT_X]], [[Y:%.*]]62; CHECK-NEXT: ret i8 [[ASHR]]63;64 %not_x = xor i8 %x, -165 call void @use8(i8 %not_x)66 %ashr = ashr i8 %not_x, %y67 ret i8 %ashr68}69