[llvm] 42dccf9 - [LoongArch] Implement isLegalAddImmediate
Weining Lu via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 24 02:18:42 PDT 2023
Author: WANG Rui
Date: 2023-07-24T17:17:24+08:00
New Revision: 42dccf9c16f6fd3ced938e989ed8c5f6284c5c4a
URL: https://github.com/llvm/llvm-project/commit/42dccf9c16f6fd3ced938e989ed8c5f6284c5c4a
DIFF: https://github.com/llvm/llvm-project/commit/42dccf9c16f6fd3ced938e989ed8c5f6284c5c4a.diff
LOG: [LoongArch] Implement isLegalAddImmediate
This brings a trivial improvement in the and-add-lsr.ll test case.
Signed-off-by: WANG Rui <wangrui at loongson.cn>
Reviewed By: SixWeining, xen0n
Differential Revision: https://reviews.llvm.org/D154762
Added:
Modified:
llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
llvm/lib/Target/LoongArch/LoongArchISelLowering.h
llvm/test/CodeGen/LoongArch/ir-instruction/and.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp b/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
index 4977b8e6f9878a..eb39bb22de662f 100644
--- a/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
+++ b/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
@@ -3247,6 +3247,10 @@ bool LoongArchTargetLowering::isLegalAddressingMode(const DataLayout &DL,
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())
diff --git a/llvm/lib/Target/LoongArch/LoongArchISelLowering.h b/llvm/lib/Target/LoongArch/LoongArchISelLowering.h
index 3fae3d5669187c..e8a4130dca08ec 100644
--- a/llvm/lib/Target/LoongArch/LoongArchISelLowering.h
+++ b/llvm/lib/Target/LoongArch/LoongArchISelLowering.h
@@ -202,6 +202,8 @@ class LoongArchTargetLowering : public TargetLowering {
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; }
diff --git a/llvm/test/CodeGen/LoongArch/ir-instruction/and.ll b/llvm/test/CodeGen/LoongArch/ir-instruction/and.ll
index 0604edccb4fe0b..bf8d8e20d9ab27 100644
--- a/llvm/test/CodeGen/LoongArch/ir-instruction/and.ll
+++ b/llvm/test/CodeGen/LoongArch/ir-instruction/and.ll
@@ -428,16 +428,14 @@ define i64 @and_i64_0xfff0_multiple_times(i64 %a, i64 %b, i64 %c) {
define i32 @and_add_lsr(i32 %x, i32 %y) {
; LA32-LABEL: and_add_lsr:
; LA32: # %bb.0:
-; LA32-NEXT: ori $a2, $zero, 4095
-; LA32-NEXT: add.w $a0, $a0, $a2
+; LA32-NEXT: addi.w $a0, $a0, -1
; LA32-NEXT: srli.w $a1, $a1, 20
; LA32-NEXT: and $a0, $a1, $a0
; LA32-NEXT: ret
;
; LA64-LABEL: and_add_lsr:
; LA64: # %bb.0:
-; LA64-NEXT: ori $a2, $zero, 4095
-; LA64-NEXT: add.d $a0, $a0, $a2
+; LA64-NEXT: addi.d $a0, $a0, -1
; LA64-NEXT: bstrpick.d $a1, $a1, 31, 20
; LA64-NEXT: and $a0, $a1, $a0
; LA64-NEXT: ret
More information about the llvm-commits
mailing list