[ARM] Use ADDCARRY / SUBCARRY
This is a preparatory step for D34515.
This change:
- makes nodes ISD::ADDCARRY and ISD::SUBCARRY legal for i32
- lowering is done by first converting the boolean value into the carry flag
using (_, C) ← (ARMISD::ADDC R, -1) and converted back to an integer value
using (R, _) ← (ARMISD::ADDE 0, 0, C). An ARMISD::ADDE between the two
operations does the actual addition.
- for subtraction, given that ISD::SUBCARRY second result is actually a
borrow, we need to invert the value of the second operand and result before
and after using ARMISD::SUBE. We need to invert the carry result of
ARMISD::SUBE to preserve the semantics.
- given that the generic combiner may lower ISD::ADDCARRY and
ISD::SUBCARRYinto ISD::UADDO and ISD::USUBO we need to update their lowering
as well otherwise i64 operations now would require branches. This implies
updating the corresponding test for unsigned.
- add new combiner to remove the redundant conversions from/to carry flags
to/from boolean values (ARMISD::ADDC (ARMISD::ADDE 0, 0, C), -1) → C
- fixes PR34045
- fixes PR34564
- fixes PR35103
Differential Revision: https://reviews.llvm.org/D35192
llvm-svn: 320355
2017-12-11 13:13:45 +01:00
|
|
|
; RUN: llc < %s -mtriple=arm-linux -mcpu=generic -verify-machineinstrs | FileCheck %s --check-prefix=CHECK --check-prefix=ARM
|
|
|
|
; RUN: llc < %s -mtriple=thumbv6m-eabi -verify-machineinstrs | FileCheck %s --check-prefix=CHECK --check-prefix=THUMBV6
|
|
|
|
; RUN: llc < %s -mtriple=thumbv7-eabi -verify-machineinstrs | FileCheck %s --check-prefix=CHECK --check-prefix=THUMBV7
|
2014-05-09 19:02:49 +02:00
|
|
|
|
|
|
|
define i32 @uadd_overflow(i32 %a, i32 %b) #0 {
|
|
|
|
%sadd = tail call { i32, i1 } @llvm.uadd.with.overflow.i32(i32 %a, i32 %b)
|
|
|
|
%1 = extractvalue { i32, i1 } %sadd, 1
|
|
|
|
%2 = zext i1 %1 to i32
|
|
|
|
ret i32 %2
|
|
|
|
|
|
|
|
; CHECK-LABEL: uadd_overflow:
|
[ARM] Use ADDCARRY / SUBCARRY
This is a preparatory step for D34515.
This change:
- makes nodes ISD::ADDCARRY and ISD::SUBCARRY legal for i32
- lowering is done by first converting the boolean value into the carry flag
using (_, C) ← (ARMISD::ADDC R, -1) and converted back to an integer value
using (R, _) ← (ARMISD::ADDE 0, 0, C). An ARMISD::ADDE between the two
operations does the actual addition.
- for subtraction, given that ISD::SUBCARRY second result is actually a
borrow, we need to invert the value of the second operand and result before
and after using ARMISD::SUBE. We need to invert the carry result of
ARMISD::SUBE to preserve the semantics.
- given that the generic combiner may lower ISD::ADDCARRY and
ISD::SUBCARRYinto ISD::UADDO and ISD::USUBO we need to update their lowering
as well otherwise i64 operations now would require branches. This implies
updating the corresponding test for unsigned.
- add new combiner to remove the redundant conversions from/to carry flags
to/from boolean values (ARMISD::ADDC (ARMISD::ADDE 0, 0, C), -1) → C
- fixes PR34045
- fixes PR34564
- fixes PR35103
Differential Revision: https://reviews.llvm.org/D35192
llvm-svn: 320355
2017-12-11 13:13:45 +01:00
|
|
|
|
|
|
|
; ARM: adds r[[R0:[0-9]+]], r[[R0]], r[[R1:[0-9]+]]
|
|
|
|
; ARM: mov r[[R2:[0-9]+]], #0
|
|
|
|
; ARM: adc r[[R0]], r[[R2]], #0
|
|
|
|
|
|
|
|
; THUMBV6: movs r[[R2:[0-9]+]], #0
|
|
|
|
; THUMBV6: adds r[[R0:[0-9]+]], r[[R0]], r[[R1:[0-9]+]]
|
|
|
|
; THUMBV6: adcs r[[R2]], r[[R2]]
|
|
|
|
; THUMBV6: mov r[[R0]], r[[R2]]
|
|
|
|
|
|
|
|
; THUMBV7: adds r[[R0:[0-9]+]], r[[R0]], r[[R1:[0-9]+]]
|
|
|
|
; THUMBV7: mov.w r[[R2:[0-9]+]], #0
|
|
|
|
; THUMBV7: adc r[[R0]], r[[R2]], #0
|
2014-05-09 19:02:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
define i32 @sadd_overflow(i32 %a, i32 %b) #0 {
|
|
|
|
%sadd = tail call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 %a, i32 %b)
|
|
|
|
%1 = extractvalue { i32, i1 } %sadd, 1
|
|
|
|
%2 = zext i1 %1 to i32
|
|
|
|
ret i32 %2
|
|
|
|
|
|
|
|
; CHECK-LABEL: sadd_overflow:
|
[ARM] Use ADDCARRY / SUBCARRY
This is a preparatory step for D34515.
This change:
- makes nodes ISD::ADDCARRY and ISD::SUBCARRY legal for i32
- lowering is done by first converting the boolean value into the carry flag
using (_, C) ← (ARMISD::ADDC R, -1) and converted back to an integer value
using (R, _) ← (ARMISD::ADDE 0, 0, C). An ARMISD::ADDE between the two
operations does the actual addition.
- for subtraction, given that ISD::SUBCARRY second result is actually a
borrow, we need to invert the value of the second operand and result before
and after using ARMISD::SUBE. We need to invert the carry result of
ARMISD::SUBE to preserve the semantics.
- given that the generic combiner may lower ISD::ADDCARRY and
ISD::SUBCARRYinto ISD::UADDO and ISD::USUBO we need to update their lowering
as well otherwise i64 operations now would require branches. This implies
updating the corresponding test for unsigned.
- add new combiner to remove the redundant conversions from/to carry flags
to/from boolean values (ARMISD::ADDC (ARMISD::ADDE 0, 0, C), -1) → C
- fixes PR34045
- fixes PR34564
- fixes PR35103
Differential Revision: https://reviews.llvm.org/D35192
llvm-svn: 320355
2017-12-11 13:13:45 +01:00
|
|
|
|
2018-01-17 20:19:05 +01:00
|
|
|
; ARM: adds r[[R2:[0-9]+]], r[[R0:[0-9]+]], r[[R1:[0-9]+]]
|
|
|
|
; ARM: mov r[[R0]], #1
|
|
|
|
; ARM: movvc r[[R0]], #0
|
|
|
|
; ARM: mov pc, lr
|
[ARM] Use ADDCARRY / SUBCARRY
This is a preparatory step for D34515.
This change:
- makes nodes ISD::ADDCARRY and ISD::SUBCARRY legal for i32
- lowering is done by first converting the boolean value into the carry flag
using (_, C) ← (ARMISD::ADDC R, -1) and converted back to an integer value
using (R, _) ← (ARMISD::ADDE 0, 0, C). An ARMISD::ADDE between the two
operations does the actual addition.
- for subtraction, given that ISD::SUBCARRY second result is actually a
borrow, we need to invert the value of the second operand and result before
and after using ARMISD::SUBE. We need to invert the carry result of
ARMISD::SUBE to preserve the semantics.
- given that the generic combiner may lower ISD::ADDCARRY and
ISD::SUBCARRYinto ISD::UADDO and ISD::USUBO we need to update their lowering
as well otherwise i64 operations now would require branches. This implies
updating the corresponding test for unsigned.
- add new combiner to remove the redundant conversions from/to carry flags
to/from boolean values (ARMISD::ADDC (ARMISD::ADDE 0, 0, C), -1) → C
- fixes PR34045
- fixes PR34564
- fixes PR35103
Differential Revision: https://reviews.llvm.org/D35192
llvm-svn: 320355
2017-12-11 13:13:45 +01:00
|
|
|
|
2018-10-26 21:32:24 +02:00
|
|
|
; THUMBV6: adds r1, r0, r1
|
|
|
|
; THUMBV6: cmp r1, r0
|
|
|
|
; THUMBV6: bvc .LBB1_2
|
[ARM] Use ADDCARRY / SUBCARRY
This is a preparatory step for D34515.
This change:
- makes nodes ISD::ADDCARRY and ISD::SUBCARRY legal for i32
- lowering is done by first converting the boolean value into the carry flag
using (_, C) ← (ARMISD::ADDC R, -1) and converted back to an integer value
using (R, _) ← (ARMISD::ADDE 0, 0, C). An ARMISD::ADDE between the two
operations does the actual addition.
- for subtraction, given that ISD::SUBCARRY second result is actually a
borrow, we need to invert the value of the second operand and result before
and after using ARMISD::SUBE. We need to invert the carry result of
ARMISD::SUBE to preserve the semantics.
- given that the generic combiner may lower ISD::ADDCARRY and
ISD::SUBCARRYinto ISD::UADDO and ISD::USUBO we need to update their lowering
as well otherwise i64 operations now would require branches. This implies
updating the corresponding test for unsigned.
- add new combiner to remove the redundant conversions from/to carry flags
to/from boolean values (ARMISD::ADDC (ARMISD::ADDE 0, 0, C), -1) → C
- fixes PR34045
- fixes PR34564
- fixes PR35103
Differential Revision: https://reviews.llvm.org/D35192
llvm-svn: 320355
2017-12-11 13:13:45 +01:00
|
|
|
|
2018-01-17 20:19:05 +01:00
|
|
|
; THUMBV7: adds r[[R2:[0-9]+]], r[[R0]], r[[R1:[0-9]+]]
|
|
|
|
; THUMBV7: mov.w r[[R0:[0-9]+]], #1
|
[ARM] Use ADDCARRY / SUBCARRY
This is a preparatory step for D34515.
This change:
- makes nodes ISD::ADDCARRY and ISD::SUBCARRY legal for i32
- lowering is done by first converting the boolean value into the carry flag
using (_, C) ← (ARMISD::ADDC R, -1) and converted back to an integer value
using (R, _) ← (ARMISD::ADDE 0, 0, C). An ARMISD::ADDE between the two
operations does the actual addition.
- for subtraction, given that ISD::SUBCARRY second result is actually a
borrow, we need to invert the value of the second operand and result before
and after using ARMISD::SUBE. We need to invert the carry result of
ARMISD::SUBE to preserve the semantics.
- given that the generic combiner may lower ISD::ADDCARRY and
ISD::SUBCARRYinto ISD::UADDO and ISD::USUBO we need to update their lowering
as well otherwise i64 operations now would require branches. This implies
updating the corresponding test for unsigned.
- add new combiner to remove the redundant conversions from/to carry flags
to/from boolean values (ARMISD::ADDC (ARMISD::ADDE 0, 0, C), -1) → C
- fixes PR34045
- fixes PR34564
- fixes PR35103
Differential Revision: https://reviews.llvm.org/D35192
llvm-svn: 320355
2017-12-11 13:13:45 +01:00
|
|
|
; THUMBV7: it vc
|
2018-01-17 20:19:05 +01:00
|
|
|
; THUMBV7: movvc r[[R0]], #0
|
2014-05-09 19:02:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @usub_overflow(i32 %a, i32 %b) #0 {
|
|
|
|
%sadd = tail call { i32, i1 } @llvm.usub.with.overflow.i32(i32 %a, i32 %b)
|
|
|
|
%1 = extractvalue { i32, i1 } %sadd, 1
|
|
|
|
%2 = zext i1 %1 to i32
|
|
|
|
ret i32 %2
|
|
|
|
|
|
|
|
; CHECK-LABEL: usub_overflow:
|
[ARM] Use ADDCARRY / SUBCARRY
This is a preparatory step for D34515.
This change:
- makes nodes ISD::ADDCARRY and ISD::SUBCARRY legal for i32
- lowering is done by first converting the boolean value into the carry flag
using (_, C) ← (ARMISD::ADDC R, -1) and converted back to an integer value
using (R, _) ← (ARMISD::ADDE 0, 0, C). An ARMISD::ADDE between the two
operations does the actual addition.
- for subtraction, given that ISD::SUBCARRY second result is actually a
borrow, we need to invert the value of the second operand and result before
and after using ARMISD::SUBE. We need to invert the carry result of
ARMISD::SUBE to preserve the semantics.
- given that the generic combiner may lower ISD::ADDCARRY and
ISD::SUBCARRYinto ISD::UADDO and ISD::USUBO we need to update their lowering
as well otherwise i64 operations now would require branches. This implies
updating the corresponding test for unsigned.
- add new combiner to remove the redundant conversions from/to carry flags
to/from boolean values (ARMISD::ADDC (ARMISD::ADDE 0, 0, C), -1) → C
- fixes PR34045
- fixes PR34564
- fixes PR35103
Differential Revision: https://reviews.llvm.org/D35192
llvm-svn: 320355
2017-12-11 13:13:45 +01:00
|
|
|
|
|
|
|
; ARM: subs r[[R0:[0-9]+]], r[[R0]], r[[R1:[0-9]+]]
|
|
|
|
; ARM: mov r[[R2:[0-9]+]], #0
|
|
|
|
; ARM: adc r[[R0]], r[[R2]], #0
|
|
|
|
; ARM: rsb r[[R0]], r[[R0]], #1
|
|
|
|
|
|
|
|
; THUMBV6: movs r[[R2:[0-9]+]], #0
|
|
|
|
; THUMBV6: subs r[[R0:[0-9]+]], r[[R0]], r[[R1:[0-9]+]]
|
|
|
|
; THUMBV6: adcs r[[R2]], r[[R2]]
|
|
|
|
; THUMBV6: movs r[[R0]], #1
|
|
|
|
; THUMBV6: subs r[[R0]], r[[R0]], r[[R2]]
|
|
|
|
|
|
|
|
; THUMBV7: subs r[[R0:[0-9]+]], r[[R0]], r[[R1:[0-9]+]]
|
|
|
|
; THUMBV7: mov.w r[[R2:[0-9]+]], #0
|
|
|
|
; THUMBV7: adc r[[R0]], r[[R2]], #0
|
|
|
|
; THUMBV7: rsb.w r[[R0]], r[[R0]], #1
|
|
|
|
|
|
|
|
; We should know that the overflow is just 1 bit,
|
|
|
|
; no need to clear any other bit
|
|
|
|
; CHECK-NOT: and
|
2014-05-09 19:02:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @ssub_overflow(i32 %a, i32 %b) #0 {
|
|
|
|
%sadd = tail call { i32, i1 } @llvm.ssub.with.overflow.i32(i32 %a, i32 %b)
|
|
|
|
%1 = extractvalue { i32, i1 } %sadd, 1
|
|
|
|
%2 = zext i1 %1 to i32
|
|
|
|
ret i32 %2
|
|
|
|
|
|
|
|
; CHECK-LABEL: ssub_overflow:
|
[ARM] Use ADDCARRY / SUBCARRY
This is a preparatory step for D34515.
This change:
- makes nodes ISD::ADDCARRY and ISD::SUBCARRY legal for i32
- lowering is done by first converting the boolean value into the carry flag
using (_, C) ← (ARMISD::ADDC R, -1) and converted back to an integer value
using (R, _) ← (ARMISD::ADDE 0, 0, C). An ARMISD::ADDE between the two
operations does the actual addition.
- for subtraction, given that ISD::SUBCARRY second result is actually a
borrow, we need to invert the value of the second operand and result before
and after using ARMISD::SUBE. We need to invert the carry result of
ARMISD::SUBE to preserve the semantics.
- given that the generic combiner may lower ISD::ADDCARRY and
ISD::SUBCARRYinto ISD::UADDO and ISD::USUBO we need to update their lowering
as well otherwise i64 operations now would require branches. This implies
updating the corresponding test for unsigned.
- add new combiner to remove the redundant conversions from/to carry flags
to/from boolean values (ARMISD::ADDC (ARMISD::ADDE 0, 0, C), -1) → C
- fixes PR34045
- fixes PR34564
- fixes PR35103
Differential Revision: https://reviews.llvm.org/D35192
llvm-svn: 320355
2017-12-11 13:13:45 +01:00
|
|
|
|
|
|
|
; ARM: mov r[[R2]], #1
|
|
|
|
; ARM: cmp r[[R0]], r[[R1]]
|
|
|
|
; ARM: movvc r[[R2]], #0
|
|
|
|
|
2018-10-26 21:32:24 +02:00
|
|
|
; THUMBV6: cmp r0, r1
|
|
|
|
; THUMBV6: bvc .LBB3_2
|
[ARM] Use ADDCARRY / SUBCARRY
This is a preparatory step for D34515.
This change:
- makes nodes ISD::ADDCARRY and ISD::SUBCARRY legal for i32
- lowering is done by first converting the boolean value into the carry flag
using (_, C) ← (ARMISD::ADDC R, -1) and converted back to an integer value
using (R, _) ← (ARMISD::ADDE 0, 0, C). An ARMISD::ADDE between the two
operations does the actual addition.
- for subtraction, given that ISD::SUBCARRY second result is actually a
borrow, we need to invert the value of the second operand and result before
and after using ARMISD::SUBE. We need to invert the carry result of
ARMISD::SUBE to preserve the semantics.
- given that the generic combiner may lower ISD::ADDCARRY and
ISD::SUBCARRYinto ISD::UADDO and ISD::USUBO we need to update their lowering
as well otherwise i64 operations now would require branches. This implies
updating the corresponding test for unsigned.
- add new combiner to remove the redundant conversions from/to carry flags
to/from boolean values (ARMISD::ADDC (ARMISD::ADDE 0, 0, C), -1) → C
- fixes PR34045
- fixes PR34564
- fixes PR35103
Differential Revision: https://reviews.llvm.org/D35192
llvm-svn: 320355
2017-12-11 13:13:45 +01:00
|
|
|
|
|
|
|
; THUMBV7: movs r[[R2:[0-9]+]], #1
|
|
|
|
; THUMBV7: cmp r[[R0:[0-9]+]], r[[R1:[0-9]+]]
|
|
|
|
; THUMBV7: it vc
|
|
|
|
; THUMBV7: movvc r[[R2]], #0
|
|
|
|
; THUMBV7: mov r[[R0]], r[[R2]]
|
2014-05-09 19:02:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
declare { i32, i1 } @llvm.uadd.with.overflow.i32(i32, i32) #1
|
|
|
|
declare { i32, i1 } @llvm.sadd.with.overflow.i32(i32, i32) #2
|
|
|
|
declare { i32, i1 } @llvm.usub.with.overflow.i32(i32, i32) #3
|
|
|
|
declare { i32, i1 } @llvm.ssub.with.overflow.i32(i32, i32) #4
|