@@ -1374,6 +1374,48 @@ define i8 @negate_select_of_op_vs_negated_op(i8 %x, i8 %y, i1 %c) {
13741374 %t2 = sub i8 %y , %t1
13751375 ret i8 %t2
13761376}
1377+
1378+ define i8 @negate_select_of_op_vs_negated_op_nsw (i8 %x , i8 %y , i1 %c ) {
1379+ ; CHECK-LABEL: @negate_select_of_op_vs_negated_op_nsw(
1380+ ; CHECK-NEXT: [[T0:%.*]] = sub i8 0, [[X:%.*]]
1381+ ; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[C:%.*]], i8 [[X]], i8 [[T0]]
1382+ ; CHECK-NEXT: [[T2:%.*]] = add i8 [[TMP1]], [[Y:%.*]]
1383+ ; CHECK-NEXT: ret i8 [[T2]]
1384+ ;
1385+ %t0 = sub nsw i8 0 , %x
1386+ %t1 = select i1 %c , i8 %t0 , i8 %x
1387+ %t2 = sub i8 %y , %t1
1388+ ret i8 %t2
1389+ }
1390+
1391+ define i8 @negate_select_of_op_vs_negated_op_nsw_commuted (i8 %x , i8 %y , i1 %c ) {
1392+ ; CHECK-LABEL: @negate_select_of_op_vs_negated_op_nsw_commuted(
1393+ ; CHECK-NEXT: [[T0:%.*]] = sub i8 0, [[X:%.*]]
1394+ ; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[C:%.*]], i8 [[T0]], i8 [[X]]
1395+ ; CHECK-NEXT: [[T2:%.*]] = add i8 [[TMP1]], [[Y:%.*]]
1396+ ; CHECK-NEXT: ret i8 [[T2]]
1397+ ;
1398+ %t0 = sub nsw i8 0 , %x
1399+ %t1 = select i1 %c , i8 %x , i8 %t0
1400+ %t2 = sub i8 %y , %t1
1401+ ret i8 %t2
1402+ }
1403+
1404+ define i8 @negate_select_of_op_vs_negated_op_nsw_xyyx (i8 %x , i8 %y , i8 %z , i1 %c ) {
1405+ ; CHECK-LABEL: @negate_select_of_op_vs_negated_op_nsw_xyyx(
1406+ ; CHECK-NEXT: [[SUB1:%.*]] = sub i8 [[X:%.*]], [[Y:%.*]]
1407+ ; CHECK-NEXT: [[SUB2:%.*]] = sub i8 [[Y]], [[X]]
1408+ ; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[C:%.*]], i8 [[SUB2]], i8 [[SUB1]]
1409+ ; CHECK-NEXT: [[T2:%.*]] = add i8 [[TMP1]], [[Z:%.*]]
1410+ ; CHECK-NEXT: ret i8 [[T2]]
1411+ ;
1412+ %sub1 = sub nsw i8 %x , %y
1413+ %sub2 = sub nsw i8 %y , %x
1414+ %t1 = select i1 %c , i8 %sub1 , i8 %sub2
1415+ %t2 = sub i8 %z , %t1
1416+ ret i8 %t2
1417+ }
1418+
13771419define i8 @dont_negate_ordinary_select (i8 %x , i8 %y , i8 %z , i1 %c ) {
13781420; CHECK-LABEL: @dont_negate_ordinary_select(
13791421; CHECK-NEXT: [[T0:%.*]] = select i1 [[C:%.*]], i8 [[X:%.*]], i8 [[Y:%.*]]
0 commit comments