1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; RUN: opt -S < %s -instcombine | FileCheck %s 3 4; Fold 5; sub (select %Cond, %TrueVal, %FalseVal), %Op1 6; to 7; select %Cond, (sub %TrueVal, %Op1), (sub %FalseVal, %Op1) 8 9; https://bugs.llvm.org/show_bug.cgi?id=44426 10 11; Base tests 12 13define i8 @t0_sub_of_trueval(i1 %c, i8 %Op1, i8 %FalseVal) { 14; CHECK-LABEL: @t0_sub_of_trueval( 15; CHECK-NEXT: [[TMP1:%.*]] = sub i8 [[FALSEVAL:%.*]], [[OP1:%.*]] 16; CHECK-NEXT: [[R:%.*]] = select i1 [[C:%.*]], i8 0, i8 [[TMP1]], !prof !0 17; CHECK-NEXT: ret i8 [[R]] 18; 19 %o = select i1 %c, i8 %Op1, i8 %FalseVal, !prof !0 ; while there, ensure preservation of prof md 20 %r = sub i8 %o, %Op1 21 ret i8 %r 22} 23define i8 @t1_sub_of_falseval(i1 %c, i8 %TrueVal, i8 %Op1) { 24; CHECK-LABEL: @t1_sub_of_falseval( 25; CHECK-NEXT: [[TMP1:%.*]] = sub i8 [[TRUEVAL:%.*]], [[OP1:%.*]] 26; CHECK-NEXT: [[R:%.*]] = select i1 [[C:%.*]], i8 [[TMP1]], i8 0, !prof !0 27; CHECK-NEXT: ret i8 [[R]] 28; 29 %o = select i1 %c, i8 %TrueVal, i8 %Op1, !prof !0 ; while there, ensure preservation of prof md 30 %r = sub i8 %o, %Op1 31 ret i8 %r 32} 33 34; Vectors 35 36define <2 x i8> @t2_vec(i1 %c, <2 x i8> %Op1, <2 x i8> %FalseVal) { 37; CHECK-LABEL: @t2_vec( 38; CHECK-NEXT: [[TMP1:%.*]] = sub <2 x i8> [[FALSEVAL:%.*]], [[OP1:%.*]] 39; CHECK-NEXT: [[R:%.*]] = select i1 [[C:%.*]], <2 x i8> zeroinitializer, <2 x i8> [[TMP1]] 40; CHECK-NEXT: ret <2 x i8> [[R]] 41; 42 %o = select i1 %c, <2 x i8> %Op1, <2 x i8> %FalseVal 43 %r = sub <2 x i8> %o, %Op1 44 ret <2 x i8> %r 45} 46 47; Extra use 48 49declare void @use8(i8) 50 51define i8 @n3_extrause(i1 %c, i8 %Op1, i8 %FalseVal) { 52; CHECK-LABEL: @n3_extrause( 53; CHECK-NEXT: [[O:%.*]] = select i1 [[C:%.*]], i8 [[OP1:%.*]], i8 [[FALSEVAL:%.*]] 54; CHECK-NEXT: call void @use8(i8 [[O]]) 55; CHECK-NEXT: [[R:%.*]] = sub i8 [[O]], [[OP1]] 56; CHECK-NEXT: ret i8 [[R]] 57; 58 %o = select i1 %c, i8 %Op1, i8 %FalseVal 59 call void @use8(i8 %o) 60 %r = sub i8 %o, %Op1 61 ret i8 %r 62} 63 64; Negative tests 65 66define i8 @n4_wrong_hands(i1 %c, i8 %TrueVal, i8 %FalseVal, i8 %Op1) { 67; CHECK-LABEL: @n4_wrong_hands( 68; CHECK-NEXT: [[O:%.*]] = select i1 [[C:%.*]], i8 [[TRUEVAL:%.*]], i8 [[FALSEVAL:%.*]] 69; CHECK-NEXT: [[R:%.*]] = sub i8 [[O]], [[OP1:%.*]] 70; CHECK-NEXT: ret i8 [[R]] 71; 72 %o = select i1 %c, i8 %TrueVal, i8 %FalseVal ; none of the hands is %Op1 73 %r = sub i8 %o, %Op1 74 ret i8 %r 75} 76 77; CHECK: !0 = !{!"branch_weights", i32 0, i32 100} 78!0 = !{!"branch_weights", i32 0, i32 100} 79