Skip to content

Commit 22ddc33

Browse files
[Hexagon] Add Saturating add instructions
Generate the saturating add instructions for sadd.sat for scalar and vector types Co-authored-by: Jyotsna Verma <[email protected]> Change-Id: Ie768876b3c6c33aafcf725a0b688dfcb9278e62c
1 parent ee2d2bd commit 22ddc33

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

llvm/lib/Target/Hexagon/HexagonISelLowering.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1687,6 +1687,9 @@ HexagonTargetLowering::HexagonTargetLowering(const TargetMachine &TM,
16871687
setOperationAction(ISD::SRL, VT, Custom);
16881688
}
16891689

1690+
setOperationAction(ISD::SADDSAT, MVT::i32, Legal);
1691+
setOperationAction(ISD::SADDSAT, MVT::i64, Legal);
1692+
16901693
// Extending loads from (native) vectors of i8 into (native) vectors of i16
16911694
// are legal.
16921695
setLoadExtAction(ISD::EXTLOAD, MVT::v2i16, MVT::v2i8, Legal);

llvm/lib/Target/Hexagon/HexagonPatterns.td

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,6 +1517,14 @@ def: Pat<(or I32:$Rs, anyimm:$s10), (A2_orir I32:$Rs, imm:$s10)>;
15171517
def: Pat<(and I32:$Rs, anyimm:$s10), (A2_andir I32:$Rs, imm:$s10)>;
15181518
def: Pat<(sub anyimm:$s10, I32:$Rs), (A2_subri imm:$s10, I32:$Rs)>;
15191519

1520+
class OpR_RR_pat_sat<InstHexagon MI, SDNode Op, ValueType ResType,
1521+
PatFrag RxPred>
1522+
: Pat<(ResType (Op RxPred:$Rs, RxPred:$Rt)),
1523+
(MI RxPred:$Rs, RxPred:$Rt)>;
1524+
1525+
def: OpR_RR_pat_sat<A2_addsat, saddsat, i32, I32>;
1526+
def: OpR_RR_pat_sat<A2_addpsat, saddsat, i64, I64>;
1527+
15201528
def: OpR_RR_pat<A2_add, Add, i32, I32>;
15211529
def: OpR_RR_pat<A2_sub, Sub, i32, I32>;
15221530
def: OpR_RR_pat<A2_and, And, i32, I32>;

llvm/test/CodeGen/Hexagon/addsat.ll

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
; RUN: llc -march=hexagon < %s | FileCheck %s
2+
3+
; Test for saturating add instructions.
4+
5+
; CHECK-LABEL: test13
6+
; CHECK: r{{[0-9]+}} = add(r{{[0-9]+}},r{{[0-9]+}}):sat
7+
define i32 @test13(i32 %a0, i32 %a1) {
8+
entry:
9+
%add = call i32 @llvm.sadd.sat.i32(i32 %a0, i32 %a1)
10+
ret i32 %add
11+
}
12+
13+
; CHECK-LABEL: test14
14+
; CHECK: r{{[0-9]+}}:{{[0-9]+}} = add(r{{[0-9]+}}:{{[0-9]+}},r{{[0-9]+}}:{{[0-9]+}}):sat
15+
define i64 @test14(i64 %a0, i64 %a1) {
16+
entry:
17+
%add = call i64 @llvm.sadd.sat.i64(i64 %a0, i64 %a1)
18+
ret i64 %add
19+
}
20+
21+
declare i32 @llvm.sadd.sat.i32(i32, i32)
22+
declare i64 @llvm.sadd.sat.i64(i64, i64)

0 commit comments

Comments
 (0)