[llvm] 899aaff - [LoongArch] Implement isLegalICmpImmediate
Weining Lu via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 24 02:43:46 PDT 2023
Author: WANG Rui
Date: 2023-07-24T17:42:11+08:00
New Revision: 899aaffcbc3a9424453f3d3b5fb2ea3f354e3a74
URL: https://github.com/llvm/llvm-project/commit/899aaffcbc3a9424453f3d3b5fb2ea3f354e3a74
DIFF: https://github.com/llvm/llvm-project/commit/899aaffcbc3a9424453f3d3b5fb2ea3f354e3a74.diff
LOG: [LoongArch] Implement isLegalICmpImmediate
This causes a trivial improvement in the legalicmpimm.ll test case.
Signed-off-by: WANG Rui <wangrui at loongson.cn>
Reviewed By: SixWeining, xen0n
Differential Revision: https://reviews.llvm.org/D154811
Added:
Modified:
llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
llvm/lib/Target/LoongArch/LoongArchISelLowering.h
llvm/test/CodeGen/LoongArch/legalicmpimm.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp b/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
index eb39bb22de662f..b8310cdacd0a53 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::isLegalICmpImmediate(int64_t Imm) const {
+ return isInt<12>(Imm);
+}
+
bool LoongArchTargetLowering::isLegalAddImmediate(int64_t Imm) const {
return isInt<12>(Imm);
}
diff --git a/llvm/lib/Target/LoongArch/LoongArchISelLowering.h b/llvm/lib/Target/LoongArch/LoongArchISelLowering.h
index e8a4130dca08ec..883ed15483288f 100644
--- a/llvm/lib/Target/LoongArch/LoongArchISelLowering.h
+++ b/llvm/lib/Target/LoongArch/LoongArchISelLowering.h
@@ -202,6 +202,7 @@ class LoongArchTargetLowering : public TargetLowering {
unsigned AS,
Instruction *I = nullptr) const override;
+ bool isLegalICmpImmediate(int64_t Imm) const override;
bool isLegalAddImmediate(int64_t Imm) const override;
bool hasAndNotCompare(SDValue Y) const override;
diff --git a/llvm/test/CodeGen/LoongArch/legalicmpimm.ll b/llvm/test/CodeGen/LoongArch/legalicmpimm.ll
index 9e10411427a716..3dc8785631dc2c 100644
--- a/llvm/test/CodeGen/LoongArch/legalicmpimm.ll
+++ b/llvm/test/CodeGen/LoongArch/legalicmpimm.ll
@@ -5,20 +5,15 @@
define i32 @icmpimm(i32 %x) {
; LA32-LABEL: icmpimm:
; LA32: # %bb.0:
-; LA32-NEXT: lu12i.w $a1, -1
-; LA32-NEXT: and $a0, $a0, $a1
-; LA32-NEXT: lu12i.w $a1, 1
-; LA32-NEXT: xor $a0, $a0, $a1
+; LA32-NEXT: srli.w $a0, $a0, 12
+; LA32-NEXT: addi.w $a0, $a0, -1
; LA32-NEXT: sltui $a0, $a0, 1
; LA32-NEXT: ret
;
; LA64-LABEL: icmpimm:
; LA64: # %bb.0:
-; LA64-NEXT: lu12i.w $a1, -1
-; LA64-NEXT: lu32i.d $a1, 0
-; LA64-NEXT: and $a0, $a0, $a1
-; LA64-NEXT: lu12i.w $a1, 1
-; LA64-NEXT: xor $a0, $a0, $a1
+; LA64-NEXT: bstrpick.d $a0, $a0, 31, 12
+; LA64-NEXT: addi.d $a0, $a0, -1
; LA64-NEXT: sltui $a0, $a0, 1
; LA64-NEXT: ret
%1 = and i32 %x, -4096
More information about the llvm-commits
mailing list