1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; RUN: opt -passes=instcombine -S < %s | FileCheck %s 3declare void @use_i8(i8) 4define i8 @mul_selectp2_x(i8 %x, i1 %c) { 5; CHECK-LABEL: @mul_selectp2_x( 6; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[C:%.*]], i8 1, i8 2 7; CHECK-NEXT: [[R:%.*]] = shl i8 [[X:%.*]], [[TMP1]] 8; CHECK-NEXT: ret i8 [[R]] 9; 10 %s = select i1 %c, i8 2, i8 4 11 %r = mul i8 %s, %x 12 ret i8 %r 13} 14 15 16define i8 @mul_selectp2_x_propegate_nuw(i8 %x, i1 %c) { 17; CHECK-LABEL: @mul_selectp2_x_propegate_nuw( 18; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[C:%.*]], i8 1, i8 2 19; CHECK-NEXT: [[R:%.*]] = shl nuw i8 [[X:%.*]], [[TMP1]] 20; CHECK-NEXT: ret i8 [[R]] 21; 22 %s = select i1 %c, i8 2, i8 4 23 %r = mul nuw nsw i8 %s, %x 24 ret i8 %r 25} 26 27 28define i8 @mul_selectp2_x_multiuse_fixme(i8 %x, i1 %c) { 29; CHECK-LABEL: @mul_selectp2_x_multiuse_fixme( 30; CHECK-NEXT: [[S:%.*]] = select i1 [[C:%.*]], i8 2, i8 4 31; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[C]], i8 1, i8 2 32; CHECK-NEXT: [[R:%.*]] = shl i8 [[X:%.*]], [[TMP1]] 33; CHECK-NEXT: call void @use_i8(i8 [[S]]) 34; CHECK-NEXT: ret i8 [[R]] 35; 36 %s = select i1 %c, i8 2, i8 4 37 %r = mul i8 %s, %x 38 call void @use_i8(i8 %s) 39 ret i8 %r 40} 41 42define i8 @mul_selectp2_x_non_const(i8 %x, i1 %c, i8 %yy) { 43; CHECK-LABEL: @mul_selectp2_x_non_const( 44; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[C:%.*]], i8 1, i8 [[YY:%.*]] 45; CHECK-NEXT: [[R:%.*]] = shl i8 [[X:%.*]], [[TMP1]] 46; CHECK-NEXT: ret i8 [[R]] 47; 48 %y = shl i8 1, %yy 49 %s = select i1 %c, i8 2, i8 %y 50 %r = mul i8 %s, %x 51 ret i8 %r 52} 53 54define i8 @mul_selectp2_x_non_const_multiuse(i8 %x, i1 %c, i8 %yy) { 55; CHECK-LABEL: @mul_selectp2_x_non_const_multiuse( 56; CHECK-NEXT: [[Y:%.*]] = shl nuw i8 1, [[YY:%.*]] 57; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[C:%.*]], i8 1, i8 [[YY]] 58; CHECK-NEXT: [[R:%.*]] = shl i8 [[X:%.*]], [[TMP1]] 59; CHECK-NEXT: call void @use_i8(i8 [[Y]]) 60; CHECK-NEXT: ret i8 [[R]] 61; 62 %y = shl i8 1, %yy 63 %s = select i1 %c, i8 2, i8 %y 64 %r = mul i8 %s, %x 65 call void @use_i8(i8 %y) 66 ret i8 %r 67} 68 69define i8 @mul_x_selectp2(i8 %xx, i1 %c) { 70; CHECK-LABEL: @mul_x_selectp2( 71; CHECK-NEXT: [[X:%.*]] = mul i8 [[XX:%.*]], [[XX]] 72; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[C:%.*]], i8 3, i8 0 73; CHECK-NEXT: [[R:%.*]] = shl i8 [[X]], [[TMP1]] 74; CHECK-NEXT: ret i8 [[R]] 75; 76 %x = mul i8 %xx, %xx 77 %s = select i1 %c, i8 8, i8 1 78 %r = mul i8 %x, %s 79 ret i8 %r 80} 81 82define i8 @mul_select_nonp2_x_fail(i8 %x, i1 %c) { 83; CHECK-LABEL: @mul_select_nonp2_x_fail( 84; CHECK-NEXT: [[S:%.*]] = select i1 [[C:%.*]], i8 2, i8 5 85; CHECK-NEXT: [[R:%.*]] = mul i8 [[S]], [[X:%.*]] 86; CHECK-NEXT: ret i8 [[R]] 87; 88 %s = select i1 %c, i8 2, i8 5 89 %r = mul i8 %s, %x 90 ret i8 %r 91} 92 93define <2 x i8> @mul_x_selectp2_vec(<2 x i8> %xx, i1 %c) { 94; CHECK-LABEL: @mul_x_selectp2_vec( 95; CHECK-NEXT: [[X:%.*]] = mul <2 x i8> [[XX:%.*]], [[XX]] 96; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[C:%.*]], <2 x i8> <i8 3, i8 4>, <2 x i8> <i8 2, i8 0> 97; CHECK-NEXT: [[R:%.*]] = shl <2 x i8> [[X]], [[TMP1]] 98; CHECK-NEXT: ret <2 x i8> [[R]] 99; 100 %x = mul <2 x i8> %xx, %xx 101 %s = select i1 %c, <2 x i8> <i8 8, i8 16>, <2 x i8> <i8 4, i8 1> 102 %r = mul <2 x i8> %x, %s 103 ret <2 x i8> %r 104} 105 106 107define i8 @shl_add_log_may_cause_poison_pr62175_fail(i8 %x, i8 %y) { 108; CHECK-LABEL: @shl_add_log_may_cause_poison_pr62175_fail( 109; CHECK-NEXT: [[SHL:%.*]] = shl i8 4, [[X:%.*]] 110; CHECK-NEXT: [[MUL:%.*]] = mul i8 [[Y:%.*]], [[SHL]] 111; CHECK-NEXT: ret i8 [[MUL]] 112; 113 %shl = shl i8 4, %x 114 %mul = mul i8 %y, %shl 115 ret i8 %mul 116} 117 118define i8 @shl_add_log_may_cause_poison_pr62175_with_nuw(i8 %x, i8 %y) { 119; CHECK-LABEL: @shl_add_log_may_cause_poison_pr62175_with_nuw( 120; CHECK-NEXT: [[TMP1:%.*]] = add i8 [[X:%.*]], 2 121; CHECK-NEXT: [[MUL:%.*]] = shl i8 [[Y:%.*]], [[TMP1]] 122; CHECK-NEXT: ret i8 [[MUL]] 123; 124 %shl = shl nuw i8 4, %x 125 %mul = mul i8 %y, %shl 126 ret i8 %mul 127} 128 129define i8 @shl_add_log_may_cause_poison_pr62175_with_nsw(i8 %x, i8 %y) { 130; CHECK-LABEL: @shl_add_log_may_cause_poison_pr62175_with_nsw( 131; CHECK-NEXT: [[TMP1:%.*]] = add i8 [[X:%.*]], 2 132; CHECK-NEXT: [[MUL:%.*]] = shl i8 [[Y:%.*]], [[TMP1]] 133; CHECK-NEXT: ret i8 [[MUL]] 134; 135 %shl = shl nsw i8 4, %x 136 %mul = mul i8 %y, %shl 137 ret i8 %mul 138} 139