[PATCH] D154762: [LoongArch] Implement isLegalAddImmediate

hev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 10 00:29:10 PDT 2023


hev updated this revision to Diff 538528.
hev edited the summary of this revision.
hev added a comment.

Rebase.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154762

Files:
  llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
  llvm/lib/Target/LoongArch/LoongArchISelLowering.h
  llvm/test/CodeGen/LoongArch/and-add-lsr.ll


Index: llvm/test/CodeGen/LoongArch/and-add-lsr.ll
===================================================================
--- llvm/test/CodeGen/LoongArch/and-add-lsr.ll
+++ llvm/test/CodeGen/LoongArch/and-add-lsr.ll
@@ -5,16 +5,14 @@
 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
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.538528.patch
Type: text/x-patch
Size: 1878 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230710/1b1316b6/attachment.bin>


More information about the llvm-commits mailing list