-
Notifications
You must be signed in to change notification settings - Fork 14.5k
[Hexagon] Add saturating add instructions #148132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-backend-hexagon Author: None (aankit-ca) ChangesGenerate the saturating add instructions for sadd.sat sadd.sat.i32 -> A2_addsat Full diff: https://github.com/llvm/llvm-project/pull/148132.diff 3 Files Affected:
diff --git a/llvm/lib/Target/Hexagon/HexagonISelLowering.cpp b/llvm/lib/Target/Hexagon/HexagonISelLowering.cpp
index 00925ed42fcd4..d123a06cc5d9e 100644
--- a/llvm/lib/Target/Hexagon/HexagonISelLowering.cpp
+++ b/llvm/lib/Target/Hexagon/HexagonISelLowering.cpp
@@ -1687,6 +1687,9 @@ HexagonTargetLowering::HexagonTargetLowering(const TargetMachine &TM,
setOperationAction(ISD::SRL, VT, Custom);
}
+ setOperationAction(ISD::SADDSAT, MVT::i32, Legal);
+ setOperationAction(ISD::SADDSAT, MVT::i64, Legal);
+
// Extending loads from (native) vectors of i8 into (native) vectors of i16
// are legal.
setLoadExtAction(ISD::EXTLOAD, MVT::v2i16, MVT::v2i8, Legal);
diff --git a/llvm/lib/Target/Hexagon/HexagonPatterns.td b/llvm/lib/Target/Hexagon/HexagonPatterns.td
index 2a991bafbf148..2337f185c7b36 100644
--- a/llvm/lib/Target/Hexagon/HexagonPatterns.td
+++ b/llvm/lib/Target/Hexagon/HexagonPatterns.td
@@ -1517,6 +1517,14 @@ def: Pat<(or I32:$Rs, anyimm:$s10), (A2_orir I32:$Rs, imm:$s10)>;
def: Pat<(and I32:$Rs, anyimm:$s10), (A2_andir I32:$Rs, imm:$s10)>;
def: Pat<(sub anyimm:$s10, I32:$Rs), (A2_subri imm:$s10, I32:$Rs)>;
+class OpR_RR_pat_sat<InstHexagon MI, SDNode Op, ValueType ResType,
+ PatFrag RxPred>
+ : Pat<(ResType (Op RxPred:$Rs, RxPred:$Rt)),
+ (MI RxPred:$Rs, RxPred:$Rt)>;
+
+def: OpR_RR_pat_sat<A2_addsat, saddsat, i32, I32>;
+def: OpR_RR_pat_sat<A2_addpsat, saddsat, i64, I64>;
+
def: OpR_RR_pat<A2_add, Add, i32, I32>;
def: OpR_RR_pat<A2_sub, Sub, i32, I32>;
def: OpR_RR_pat<A2_and, And, i32, I32>;
diff --git a/llvm/test/CodeGen/Hexagon/addsat.ll b/llvm/test/CodeGen/Hexagon/addsat.ll
new file mode 100644
index 0000000000000..f958171ee3ae2
--- /dev/null
+++ b/llvm/test/CodeGen/Hexagon/addsat.ll
@@ -0,0 +1,22 @@
+; RUN: llc -march=hexagon < %s | FileCheck %s
+
+; Test for saturating add instructions.
+
+; CHECK-LABEL: test13
+; CHECK: r{{[0-9]+}} = add(r{{[0-9]+}},r{{[0-9]+}}):sat
+define i32 @test13(i32 %a0, i32 %a1) {
+entry:
+ %add = call i32 @llvm.sadd.sat.i32(i32 %a0, i32 %a1)
+ ret i32 %add
+}
+
+; CHECK-LABEL: test14
+; CHECK: r{{[0-9]+}}:{{[0-9]+}} = add(r{{[0-9]+}}:{{[0-9]+}},r{{[0-9]+}}:{{[0-9]+}}):sat
+define i64 @test14(i64 %a0, i64 %a1) {
+entry:
+ %add = call i64 @llvm.sadd.sat.i64(i64 %a0, i64 %a1)
+ ret i64 %add
+}
+
+declare i32 @llvm.sadd.sat.i32(i32, i32)
+declare i64 @llvm.sadd.sat.i64(i64, i64)
|
630001b
to
22ddc33
Compare
Hi Ankit, I dont see any changes for the vector instructions. |
yeah - either the commit message is wrong or the vector instructions were omitted. |
Agreed. The commit message needs to be updated. The changes in the PR are only for the scalar. |
Generate the saturating add instructions for sadd.sat for scalar and vector types Co-authored-by: Jyotsna Verma <[email protected]> Change-Id: Ie768876b3c6c33aafcf725a0b688dfcb9278e62c
My mistake, I forgot to git commit some of the changes. Fixed it now |
22ddc33
to
8a03aab
Compare
✅ With the latest revision this PR passed the C/C++ code formatter. |
Change-Id: I52264b23b07eb4aba5bed1dcab9bb78e3ac1985b
Generate the saturating add instructions for sadd.sat for scalar and vector instructions
Co-authored-by: Jyotsna Verma [email protected]