[PATCH] D154811: [LoongArch] Implement isLegalICmpImmediate

hev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 9 19:30:37 PDT 2023


hev created this revision.
hev added reviewers: SixWeining, xen0n.
Herald added subscribers: asbirlea, hiraditya.
Herald added a project: All.
hev requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This causes a trivial improvement in the legalicmpimm.ll test case.

Signed-off-by: WANG Rui <wangrui at loongson.cn>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154811

Files:
  llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
  llvm/lib/Target/LoongArch/LoongArchISelLowering.h
  llvm/test/CodeGen/LoongArch/legalicmpimm.ll


Index: llvm/test/CodeGen/LoongArch/legalicmpimm.ll
===================================================================
--- llvm/test/CodeGen/LoongArch/legalicmpimm.ll
+++ llvm/test/CodeGen/LoongArch/legalicmpimm.ll
@@ -4,11 +4,8 @@
 define i32 @icmpimm(i32 %x) {
 ; CHECK-LABEL: icmpimm:
 ; CHECK:       # %bb.0:
-; CHECK-NEXT:    lu12i.w $a1, -1
-; CHECK-NEXT:    lu32i.d $a1, 0
-; CHECK-NEXT:    and $a0, $a0, $a1
-; CHECK-NEXT:    lu12i.w $a1, 1
-; CHECK-NEXT:    xor $a0, $a0, $a1
+; CHECK-NEXT:    bstrpick.d $a0, $a0, 31, 12
+; CHECK-NEXT:    addi.d $a0, $a0, -1
 ; CHECK-NEXT:    sltui $a0, $a0, 1
 ; CHECK-NEXT:    ret
   %1 = and i32 %x, -4096
Index: llvm/lib/Target/LoongArch/LoongArchISelLowering.h
===================================================================
--- llvm/lib/Target/LoongArch/LoongArchISelLowering.h
+++ llvm/lib/Target/LoongArch/LoongArchISelLowering.h
@@ -202,6 +202,7 @@
                              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;
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::isLegalICmpImmediate(int64_t Imm) const {
+  return isInt<12>(Imm);
+}
+
 bool LoongArchTargetLowering::isLegalAddImmediate(int64_t Imm) const {
   return isInt<12>(Imm);
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154811.538495.patch
Type: text/x-patch
Size: 1680 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230710/6c5fbe9e/attachment.bin>


More information about the llvm-commits mailing list