Skip to content

Commit

Permalink
[LoongArch] Implement isLegalICmpImmediate
Browse files Browse the repository at this point in the history
This causes a trivial improvement in the legalicmpimm.ll test case.

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

Reviewed By: SixWeining, xen0n

Differential Revision: https://reviews.llvm.org/D154811
  • Loading branch information
heiher authored and SixWeining committed Jul 24, 2023
1 parent 0cceea9 commit 899aaff
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 4 additions & 0 deletions llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Target/LoongArch/LoongArchISelLowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 4 additions & 9 deletions llvm/test/CodeGen/LoongArch/legalicmpimm.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 899aaff

Please sign in to comment.