292 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt < %s -passes=instcombine -S | FileCheck %s3 4declare void @use8(i8)5 6define i6 @add_shl_same_amount(i6 %x, i6 %y, i6 %z) {7; CHECK-LABEL: @add_shl_same_amount(8; CHECK-NEXT: [[TMP1:%.*]] = add i6 [[X:%.*]], [[Y:%.*]]9; CHECK-NEXT: [[DIFF:%.*]] = shl i6 [[TMP1]], [[Z:%.*]]10; CHECK-NEXT: ret i6 [[DIFF]]11;12 %xs = shl i6 %x, %z13 %ys = shl i6 %y, %z14 %diff = add i6 %xs, %ys15 ret i6 %diff16}17 18define <2 x i4> @add_shl_same_amount_nsw(<2 x i4> %x, <2 x i4> %y, <2 x i4> %z) {19; CHECK-LABEL: @add_shl_same_amount_nsw(20; CHECK-NEXT: [[TMP1:%.*]] = add nsw <2 x i4> [[X:%.*]], [[Y:%.*]]21; CHECK-NEXT: [[DIFF:%.*]] = shl nsw <2 x i4> [[TMP1]], [[Z:%.*]]22; CHECK-NEXT: ret <2 x i4> [[DIFF]]23;24 %xs = shl nsw <2 x i4> %x, %z25 %ys = shl nsw <2 x i4> %y, %z26 %diff = add nsw <2 x i4> %xs, %ys27 ret <2 x i4> %diff28}29 30define i64 @add_shl_same_amount_nuw(i64 %x, i64 %y, i64 %z) {31; CHECK-LABEL: @add_shl_same_amount_nuw(32; CHECK-NEXT: [[TMP1:%.*]] = add nuw i64 [[X:%.*]], [[Y:%.*]]33; CHECK-NEXT: [[DIFF:%.*]] = shl nuw i64 [[TMP1]], [[Z:%.*]]34; CHECK-NEXT: ret i64 [[DIFF]]35;36 %xs = shl nuw i64 %x, %z37 %ys = shl nuw i64 %y, %z38 %diff = add nuw i64 %xs, %ys39 ret i64 %diff40}41 42define i8 @add_shl_same_amount_nsw_extra_use1(i8 %x, i8 %y, i8 %z) {43; CHECK-LABEL: @add_shl_same_amount_nsw_extra_use1(44; CHECK-NEXT: [[XS:%.*]] = shl nuw nsw i8 [[X:%.*]], [[Z:%.*]]45; CHECK-NEXT: call void @use8(i8 [[XS]])46; CHECK-NEXT: [[TMP1:%.*]] = add nsw i8 [[X]], [[Y:%.*]]47; CHECK-NEXT: [[DIFF:%.*]] = shl nsw i8 [[TMP1]], [[Z]]48; CHECK-NEXT: ret i8 [[DIFF]]49;50 %xs = shl nsw nuw i8 %x, %z51 call void @use8(i8 %xs)52 %ys = shl nsw nuw i8 %y, %z53 %diff = add nsw i8 %xs, %ys54 ret i8 %diff55}56 57define i8 @add_shl_same_amount_nuw_extra_use2(i8 %x, i8 %y, i8 %z) {58; CHECK-LABEL: @add_shl_same_amount_nuw_extra_use2(59; CHECK-NEXT: [[YS:%.*]] = shl nuw nsw i8 [[Y:%.*]], [[Z:%.*]]60; CHECK-NEXT: call void @use8(i8 [[YS]])61; CHECK-NEXT: [[TMP1:%.*]] = add nuw i8 [[X:%.*]], [[Y]]62; CHECK-NEXT: [[DIFF:%.*]] = shl nuw i8 [[TMP1]], [[Z]]63; CHECK-NEXT: ret i8 [[DIFF]]64;65 %xs = shl nuw i8 %x, %z66 %ys = shl nsw nuw i8 %y, %z67 call void @use8(i8 %ys)68 %diff = add nsw nuw i8 %xs, %ys69 ret i8 %diff70}71 72define i8 @add_shl_same_amount_nsw_nuw_extra_use3(i8 %x, i8 %y, i8 %z) {73; CHECK-LABEL: @add_shl_same_amount_nsw_nuw_extra_use3(74; CHECK-NEXT: [[XS:%.*]] = shl nuw nsw i8 [[X:%.*]], [[Z:%.*]]75; CHECK-NEXT: call void @use8(i8 [[XS]])76; CHECK-NEXT: [[YS:%.*]] = shl nuw nsw i8 [[Y:%.*]], [[Z]]77; CHECK-NEXT: call void @use8(i8 [[YS]])78; CHECK-NEXT: [[DIFF:%.*]] = add nuw nsw i8 [[XS]], [[YS]]79; CHECK-NEXT: ret i8 [[DIFF]]80;81 %xs = shl nsw nuw i8 %x, %z82 call void @use8(i8 %xs)83 %ys = shl nsw nuw i8 %y, %z84 call void @use8(i8 %ys)85 %diff = add nsw nuw i8 %xs, %ys86 ret i8 %diff87}88 89define i6 @add_shl_same_amount_partial_nsw1(i6 %x, i6 %y, i6 %z) {90; CHECK-LABEL: @add_shl_same_amount_partial_nsw1(91; CHECK-NEXT: [[TMP1:%.*]] = add i6 [[X:%.*]], [[Y:%.*]]92; CHECK-NEXT: [[DIFF:%.*]] = shl i6 [[TMP1]], [[Z:%.*]]93; CHECK-NEXT: ret i6 [[DIFF]]94;95 %xs = shl nsw i6 %x, %z96 %ys = shl nsw i6 %y, %z97 %diff = add i6 %xs, %ys98 ret i6 %diff99}100 101define i6 @add_shl_same_amount_partial_nsw2(i6 %x, i6 %y, i6 %z) {102; CHECK-LABEL: @add_shl_same_amount_partial_nsw2(103; CHECK-NEXT: [[TMP1:%.*]] = add i6 [[X:%.*]], [[Y:%.*]]104; CHECK-NEXT: [[DIFF:%.*]] = shl i6 [[TMP1]], [[Z:%.*]]105; CHECK-NEXT: ret i6 [[DIFF]]106;107 %xs = shl i6 %x, %z108 %ys = shl nsw i6 %y, %z109 %diff = add nsw i6 %xs, %ys110 ret i6 %diff111}112 113define i6 @add_shl_same_amount_partial_nuw1(i6 %x, i6 %y, i6 %z) {114; CHECK-LABEL: @add_shl_same_amount_partial_nuw1(115; CHECK-NEXT: [[TMP1:%.*]] = add i6 [[X:%.*]], [[Y:%.*]]116; CHECK-NEXT: [[DIFF:%.*]] = shl i6 [[TMP1]], [[Z:%.*]]117; CHECK-NEXT: ret i6 [[DIFF]]118;119 %xs = shl nuw i6 %x, %z120 %ys = shl nuw i6 %y, %z121 %diff = add i6 %xs, %ys122 ret i6 %diff123}124 125define i6 @add_shl_same_amount_partial_nuw2(i6 %x, i6 %y, i6 %z) {126; CHECK-LABEL: @add_shl_same_amount_partial_nuw2(127; CHECK-NEXT: [[TMP1:%.*]] = add i6 [[X:%.*]], [[Y:%.*]]128; CHECK-NEXT: [[DIFF:%.*]] = shl i6 [[TMP1]], [[Z:%.*]]129; CHECK-NEXT: ret i6 [[DIFF]]130;131 %xs = shl nuw i6 %x, %z132 %ys = shl i6 %y, %z133 %diff = add nuw i6 %xs, %ys134 ret i6 %diff135}136 137define i6 @sub_shl_same_amount(i6 %x, i6 %y, i6 %z) {138; CHECK-LABEL: @sub_shl_same_amount(139; CHECK-NEXT: [[TMP1:%.*]] = sub i6 [[X:%.*]], [[Y:%.*]]140; CHECK-NEXT: [[DIFF:%.*]] = shl i6 [[TMP1]], [[Z:%.*]]141; CHECK-NEXT: ret i6 [[DIFF]]142;143 %xs = shl i6 %x, %z144 %ys = shl i6 %y, %z145 %diff = sub i6 %xs, %ys146 ret i6 %diff147}148 149define <2 x i4> @sub_shl_same_amount_nsw(<2 x i4> %x, <2 x i4> %y, <2 x i4> %z) {150; CHECK-LABEL: @sub_shl_same_amount_nsw(151; CHECK-NEXT: [[TMP1:%.*]] = sub nsw <2 x i4> [[X:%.*]], [[Y:%.*]]152; CHECK-NEXT: [[DIFF:%.*]] = shl nsw <2 x i4> [[TMP1]], [[Z:%.*]]153; CHECK-NEXT: ret <2 x i4> [[DIFF]]154;155 %xs = shl nsw <2 x i4> %x, %z156 %ys = shl nsw <2 x i4> %y, %z157 %diff = sub nsw <2 x i4> %xs, %ys158 ret <2 x i4> %diff159}160 161define i64 @sub_shl_same_amount_nuw(i64 %x, i64 %y, i64 %z) {162; CHECK-LABEL: @sub_shl_same_amount_nuw(163; CHECK-NEXT: [[TMP1:%.*]] = sub nuw i64 [[X:%.*]], [[Y:%.*]]164; CHECK-NEXT: [[DIFF:%.*]] = shl nuw i64 [[TMP1]], [[Z:%.*]]165; CHECK-NEXT: ret i64 [[DIFF]]166;167 %xs = shl nuw i64 %x, %z168 %ys = shl nuw i64 %y, %z169 %diff = sub nuw i64 %xs, %ys170 ret i64 %diff171}172 173define i8 @sub_shl_same_amount_nsw_extra_use1(i8 %x, i8 %y, i8 %z) {174; CHECK-LABEL: @sub_shl_same_amount_nsw_extra_use1(175; CHECK-NEXT: [[XS:%.*]] = shl nuw nsw i8 [[X:%.*]], [[Z:%.*]]176; CHECK-NEXT: call void @use8(i8 [[XS]])177; CHECK-NEXT: [[TMP1:%.*]] = sub nsw i8 [[X]], [[Y:%.*]]178; CHECK-NEXT: [[DIFF:%.*]] = shl nsw i8 [[TMP1]], [[Z]]179; CHECK-NEXT: ret i8 [[DIFF]]180;181 %xs = shl nsw nuw i8 %x, %z182 call void @use8(i8 %xs)183 %ys = shl nsw nuw i8 %y, %z184 %diff = sub nsw i8 %xs, %ys185 ret i8 %diff186}187 188define i8 @sub_shl_same_amount_nuw_extra_use2(i8 %x, i8 %y, i8 %z) {189; CHECK-LABEL: @sub_shl_same_amount_nuw_extra_use2(190; CHECK-NEXT: [[YS:%.*]] = shl nuw nsw i8 [[Y:%.*]], [[Z:%.*]]191; CHECK-NEXT: call void @use8(i8 [[YS]])192; CHECK-NEXT: [[TMP1:%.*]] = sub nuw i8 [[X:%.*]], [[Y]]193; CHECK-NEXT: [[DIFF:%.*]] = shl nuw i8 [[TMP1]], [[Z]]194; CHECK-NEXT: ret i8 [[DIFF]]195;196 %xs = shl nuw i8 %x, %z197 %ys = shl nsw nuw i8 %y, %z198 call void @use8(i8 %ys)199 %diff = sub nsw nuw i8 %xs, %ys200 ret i8 %diff201}202 203define i8 @sub_shl_same_amount_nsw_nuw_extra_use3(i8 %x, i8 %y, i8 %z) {204; CHECK-LABEL: @sub_shl_same_amount_nsw_nuw_extra_use3(205; CHECK-NEXT: [[XS:%.*]] = shl nuw nsw i8 [[X:%.*]], [[Z:%.*]]206; CHECK-NEXT: call void @use8(i8 [[XS]])207; CHECK-NEXT: [[YS:%.*]] = shl nuw nsw i8 [[Y:%.*]], [[Z]]208; CHECK-NEXT: call void @use8(i8 [[YS]])209; CHECK-NEXT: [[DIFF:%.*]] = sub nuw nsw i8 [[XS]], [[YS]]210; CHECK-NEXT: ret i8 [[DIFF]]211;212 %xs = shl nsw nuw i8 %x, %z213 call void @use8(i8 %xs)214 %ys = shl nsw nuw i8 %y, %z215 call void @use8(i8 %ys)216 %diff = sub nsw nuw i8 %xs, %ys217 ret i8 %diff218}219 220define i6 @sub_shl_same_amount_partial_nsw1(i6 %x, i6 %y, i6 %z) {221; CHECK-LABEL: @sub_shl_same_amount_partial_nsw1(222; CHECK-NEXT: [[TMP1:%.*]] = sub i6 [[X:%.*]], [[Y:%.*]]223; CHECK-NEXT: [[DIFF:%.*]] = shl i6 [[TMP1]], [[Z:%.*]]224; CHECK-NEXT: ret i6 [[DIFF]]225;226 %xs = shl nsw i6 %x, %z227 %ys = shl nsw i6 %y, %z228 %diff = sub i6 %xs, %ys229 ret i6 %diff230}231 232define i6 @sub_shl_same_amount_partial_nsw2(i6 %x, i6 %y, i6 %z) {233; CHECK-LABEL: @sub_shl_same_amount_partial_nsw2(234; CHECK-NEXT: [[TMP1:%.*]] = sub i6 [[X:%.*]], [[Y:%.*]]235; CHECK-NEXT: [[DIFF:%.*]] = shl i6 [[TMP1]], [[Z:%.*]]236; CHECK-NEXT: ret i6 [[DIFF]]237;238 %xs = shl i6 %x, %z239 %ys = shl nsw i6 %y, %z240 %diff = sub nsw i6 %xs, %ys241 ret i6 %diff242}243 244define i6 @sub_shl_same_amount_partial_nuw1(i6 %x, i6 %y, i6 %z) {245; CHECK-LABEL: @sub_shl_same_amount_partial_nuw1(246; CHECK-NEXT: [[TMP1:%.*]] = sub i6 [[X:%.*]], [[Y:%.*]]247; CHECK-NEXT: [[DIFF:%.*]] = shl i6 [[TMP1]], [[Z:%.*]]248; CHECK-NEXT: ret i6 [[DIFF]]249;250 %xs = shl nuw i6 %x, %z251 %ys = shl nuw i6 %y, %z252 %diff = sub i6 %xs, %ys253 ret i6 %diff254}255 256define i6 @sub_shl_same_amount_partial_nuw2(i6 %x, i6 %y, i6 %z) {257; CHECK-LABEL: @sub_shl_same_amount_partial_nuw2(258; CHECK-NEXT: [[TMP1:%.*]] = sub i6 [[X:%.*]], [[Y:%.*]]259; CHECK-NEXT: [[DIFF:%.*]] = shl i6 [[TMP1]], [[Z:%.*]]260; CHECK-NEXT: ret i6 [[DIFF]]261;262 %xs = shl nuw i6 %x, %z263 %ys = shl i6 %y, %z264 %diff = sub nuw i6 %xs, %ys265 ret i6 %diff266}267 268define i8 @add_shl_same_amount_constants(i8 %z) {269; CHECK-LABEL: @add_shl_same_amount_constants(270; CHECK-NEXT: [[SUM:%.*]] = shl i8 7, [[Z:%.*]]271; CHECK-NEXT: ret i8 [[SUM]]272;273 %s1 = shl i8 4, %z274 %s2 = shl i8 3, %z275 %sum = add i8 %s1, %s2276 ret i8 %sum277}278 279define i8 @add_shl_same_amount_constants_extra_use(i8 %z) {280; CHECK-LABEL: @add_shl_same_amount_constants_extra_use(281; CHECK-NEXT: [[S1:%.*]] = shl i8 4, [[Z:%.*]]282; CHECK-NEXT: [[SUM:%.*]] = shl i8 7, [[Z]]283; CHECK-NEXT: call void @use8(i8 [[S1]])284; CHECK-NEXT: ret i8 [[SUM]]285;286 %s1 = shl i8 4, %z287 %s2 = shl i8 3, %z288 %sum = add i8 %s1, %s2289 call void @use8(i8 %s1)290 ret i8 %sum291}292