[PATCH] D154811: [LoongArch] Implement isLegalICmpImmediate

Lu Weining via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 24 02:43:53 PDT 2023


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG899aaffcbc3a: [LoongArch] Implement isLegalICmpImmediate (authored by hev, committed by SixWeining).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154811/new/

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
@@ -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
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
@@ -3247,6 +3247,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.543435.patch
Type: text/x-patch
Size: 1986 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230724/359f7740/attachment.bin>


More information about the llvm-commits mailing list