define i32 @add_to_sub(i32 %M, i32 %B) {
; CHECK-LABEL: @add_to_sub(
; CHECK-NEXT: [[A:%.*]] = mul i32 [[M:%.*]], 42
-; CHECK-NEXT: [[C:%.*]] = xor i32 [[B:%.*]], -1
-; CHECK-NEXT: [[D:%.*]] = add i32 [[A]], [[C]]
-; CHECK-NEXT: [[E:%.*]] = add i32 [[D]], 1
+; CHECK-NEXT: [[E:%.*]] = sub i32 [[A]], [[B:%.*]]
; CHECK-NEXT: ret i32 [[E]]
;
%A = mul i32 %M, 42 ; thwart complexity-based ordering
; E = (~B + A) + 1 = A - B
define i32 @add_to_sub2(i32 %A, i32 %M) {
; CHECK-LABEL: @add_to_sub2(
-; CHECK-NEXT: [[B:%.*]] = mul i32 [[M:%.*]], 42
-; CHECK-NEXT: [[C:%.*]] = xor i32 [[B]], -1
-; CHECK-NEXT: [[D:%.*]] = add i32 [[C]], [[A:%.*]]
-; CHECK-NEXT: [[E:%.*]] = add i32 [[D]], 1
+; CHECK-NEXT: [[TMP1:%.*]] = mul i32 [[M:%.*]], -42
+; CHECK-NEXT: [[E:%.*]] = add i32 [[TMP1]], [[A:%.*]]
; CHECK-NEXT: ret i32 [[E]]
;
%B = mul i32 %M, 42 ; thwart complexity-based ordering
define i32 @t0(i32 %x, i32 %y) {
; CHECK-LABEL: @t0(
-; CHECK-NEXT: [[T0:%.*]] = xor i32 [[X:%.*]], -1
-; CHECK-NEXT: [[T1:%.*]] = add i32 [[T0]], [[Y:%.*]]
-; CHECK-NEXT: [[T2:%.*]] = add i32 [[T1]], 1
+; CHECK-NEXT: [[T2:%.*]] = sub i32 [[Y:%.*]], [[X:%.*]]
; CHECK-NEXT: ret i32 [[T2]]
;
%t0 = xor i32 %x, -1
define <4 x i32> @t1_vec_splat(<4 x i32> %x, <4 x i32> %y) {
; CHECK-LABEL: @t1_vec_splat(
-; CHECK-NEXT: [[T0:%.*]] = xor <4 x i32> [[X:%.*]], <i32 -1, i32 -1, i32 -1, i32 -1>
-; CHECK-NEXT: [[T1:%.*]] = add <4 x i32> [[T0]], [[Y:%.*]]
-; CHECK-NEXT: [[T2:%.*]] = add <4 x i32> [[T1]], <i32 1, i32 1, i32 1, i32 1>
+; CHECK-NEXT: [[T2:%.*]] = sub <4 x i32> [[Y:%.*]], [[X:%.*]]
; CHECK-NEXT: ret <4 x i32> [[T2]]
;
%t0 = xor <4 x i32> %x, <i32 -1, i32 -1, i32 -1, i32 -1>
define <4 x i32> @t2_vec_undef0(<4 x i32> %x, <4 x i32> %y) {
; CHECK-LABEL: @t2_vec_undef0(
-; CHECK-NEXT: [[T0:%.*]] = xor <4 x i32> [[X:%.*]], <i32 -1, i32 -1, i32 undef, i32 -1>
-; CHECK-NEXT: [[T1:%.*]] = add <4 x i32> [[T0]], [[Y:%.*]]
-; CHECK-NEXT: [[T2:%.*]] = add <4 x i32> [[T1]], <i32 1, i32 1, i32 1, i32 1>
+; CHECK-NEXT: [[T2:%.*]] = sub <4 x i32> [[Y:%.*]], [[X:%.*]]
; CHECK-NEXT: ret <4 x i32> [[T2]]
;
%t0 = xor <4 x i32> %x, <i32 -1, i32 -1, i32 undef, i32 -1>
define <4 x i32> @t3_vec_undef1(<4 x i32> %x, <4 x i32> %y) {
; CHECK-LABEL: @t3_vec_undef1(
-; CHECK-NEXT: [[T0:%.*]] = xor <4 x i32> [[X:%.*]], <i32 -1, i32 -1, i32 -1, i32 -1>
-; CHECK-NEXT: [[T1:%.*]] = add <4 x i32> [[T0]], [[Y:%.*]]
-; CHECK-NEXT: [[T2:%.*]] = add <4 x i32> [[T1]], <i32 1, i32 1, i32 undef, i32 1>
+; CHECK-NEXT: [[T2:%.*]] = sub <4 x i32> [[Y:%.*]], [[X:%.*]]
; CHECK-NEXT: ret <4 x i32> [[T2]]
;
%t0 = xor <4 x i32> %x, <i32 -1, i32 -1, i32 -1, i32 -1>
define <4 x i32> @t4_vec_undef2(<4 x i32> %x, <4 x i32> %y) {
; CHECK-LABEL: @t4_vec_undef2(
-; CHECK-NEXT: [[T0:%.*]] = xor <4 x i32> [[X:%.*]], <i32 -1, i32 -1, i32 undef, i32 -1>
-; CHECK-NEXT: [[T1:%.*]] = add <4 x i32> [[T0]], [[Y:%.*]]
-; CHECK-NEXT: [[T2:%.*]] = add <4 x i32> [[T1]], <i32 1, i32 1, i32 undef, i32 1>
+; CHECK-NEXT: [[T2:%.*]] = sub <4 x i32> [[Y:%.*]], [[X:%.*]]
; CHECK-NEXT: ret <4 x i32> [[T2]]
;
%t0 = xor <4 x i32> %x, <i32 -1, i32 -1, i32 undef, i32 -1>
; CHECK-LABEL: @t5(
; CHECK-NEXT: [[T0:%.*]] = xor i32 [[X:%.*]], -1
; CHECK-NEXT: call void @use32(i32 [[T0]])
-; CHECK-NEXT: [[T1:%.*]] = add i32 [[T0]], [[Y:%.*]]
-; CHECK-NEXT: [[T2:%.*]] = add i32 [[T1]], 1
+; CHECK-NEXT: [[T2:%.*]] = sub i32 [[Y:%.*]], [[X]]
; CHECK-NEXT: ret i32 [[T2]]
;
%t0 = xor i32 %x, -1
; CHECK-NEXT: [[T0:%.*]] = xor i32 [[X:%.*]], -1
; CHECK-NEXT: [[T1:%.*]] = add i32 [[T0]], [[Y:%.*]]
; CHECK-NEXT: call void @use32(i32 [[T1]])
-; CHECK-NEXT: [[T2:%.*]] = add i32 [[T1]], 1
+; CHECK-NEXT: [[T2:%.*]] = sub i32 [[Y]], [[X]]
; CHECK-NEXT: ret i32 [[T2]]
;
%t0 = xor i32 %x, -1
; CHECK-NEXT: call void @use32(i32 [[T0]])
; CHECK-NEXT: [[T1:%.*]] = add i32 [[T0]], [[Y:%.*]]
; CHECK-NEXT: call void @use32(i32 [[T1]])
-; CHECK-NEXT: [[T2:%.*]] = add i32 [[T1]], 1
+; CHECK-NEXT: [[T2:%.*]] = sub i32 [[Y]], [[X]]
; CHECK-NEXT: ret i32 [[T2]]
;
%t0 = xor i32 %x, -1
; CHECK-NEXT: call void @use32(i32 [[T0]])
; CHECK-NEXT: [[T1:%.*]] = add i32 [[Y]], [[T0]]
; CHECK-NEXT: call void @use32(i32 [[T1]])
-; CHECK-NEXT: [[T2:%.*]] = add i32 [[T1]], 1
+; CHECK-NEXT: [[T2:%.*]] = sub i32 [[Y]], [[X]]
; CHECK-NEXT: ret i32 [[T2]]
;
%y = call i32 @gen32()