[PATCH] D154762: [LoongArch] Implement isLegalAddImmediate
hev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Jul 8 02:10:49 PDT 2023
hev created this revision.
hev added reviewers: SixWeining, xen0n.
hev added a project: LLVM.
Herald added a subscriber: hiraditya.
Herald added a project: All.
hev requested review of this revision.
Herald added a subscriber: llvm-commits.
This causes a trivial improvement in the lsr-legaladdimm.ll test case.
Signed-off-by: WANG Rui <wangrui at loongson.cn>
Depends on D154760 <https://reviews.llvm.org/D154760>
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D154762
Files:
llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
llvm/lib/Target/LoongArch/LoongArchISelLowering.h
llvm/test/CodeGen/LoongArch/lsr-legaladdimm.ll
Index: llvm/test/CodeGen/LoongArch/lsr-legaladdimm.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/LoongArch/lsr-legaladdimm.ll
@@ -0,0 +1,15 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc --mtriple=loongarch64 < %s | FileCheck %s
+
+define i32 @lsr_addimm(i32 %x, i32 %y) {
+; CHECK-LABEL: lsr_addimm:
+; CHECK: # %bb.0:
+; CHECK-NEXT: addi.d $a0, $a0, -1
+; CHECK-NEXT: bstrpick.d $a1, $a1, 31, 20
+; CHECK-NEXT: and $a0, $a1, $a0
+; CHECK-NEXT: ret
+ %1 = add i32 %x, 4095
+ %2 = lshr i32 %y, 20
+ %r = and i32 %2, %1
+ ret i32 %r
+}
Index: llvm/lib/Target/LoongArch/LoongArchISelLowering.h
===================================================================
--- llvm/lib/Target/LoongArch/LoongArchISelLowering.h
+++ llvm/lib/Target/LoongArch/LoongArchISelLowering.h
@@ -202,6 +202,8 @@
unsigned AS,
Instruction *I = nullptr) const override;
+ bool isLegalAddImmediate(int64_t Imm) const override;
+
bool hasAndNotCompare(SDValue Y) const override;
bool convertSelectOfConstantsToMath(EVT VT) const override { return true; }
Index: llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
===================================================================
--- llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
+++ llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
@@ -3243,6 +3243,10 @@
return true;
}
+bool LoongArchTargetLowering::isLegalAddImmediate(int64_t Imm) const {
+ return isInt<12>(Imm);
+}
+
bool LoongArchTargetLowering::hasAndNotCompare(SDValue Y) const {
// TODO: Support vectors.
if (Y.getValueType().isVector())
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154762.538336.patch
Type: text/x-patch
Size: 1745 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230708/94005abb/attachment.bin>
More information about the llvm-commits
mailing list