Skip to content

Commit 899aaff

Browse files
heiherSixWeining
authored andcommitted
[LoongArch] Implement isLegalICmpImmediate
This causes a trivial improvement in the legalicmpimm.ll test case. Signed-off-by: WANG Rui <[email protected]> Reviewed By: SixWeining, xen0n Differential Revision: https://reviews.llvm.org/D154811
1 parent 0cceea9 commit 899aaff

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3247,6 +3247,10 @@ bool LoongArchTargetLowering::isLegalAddressingMode(const DataLayout &DL,
32473247
return true;
32483248
}
32493249

3250+
bool LoongArchTargetLowering::isLegalICmpImmediate(int64_t Imm) const {
3251+
return isInt<12>(Imm);
3252+
}
3253+
32503254
bool LoongArchTargetLowering::isLegalAddImmediate(int64_t Imm) const {
32513255
return isInt<12>(Imm);
32523256
}

llvm/lib/Target/LoongArch/LoongArchISelLowering.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ class LoongArchTargetLowering : public TargetLowering {
202202
unsigned AS,
203203
Instruction *I = nullptr) const override;
204204

205+
bool isLegalICmpImmediate(int64_t Imm) const override;
205206
bool isLegalAddImmediate(int64_t Imm) const override;
206207

207208
bool hasAndNotCompare(SDValue Y) const override;

llvm/test/CodeGen/LoongArch/legalicmpimm.ll

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,15 @@
55
define i32 @icmpimm(i32 %x) {
66
; LA32-LABEL: icmpimm:
77
; LA32: # %bb.0:
8-
; LA32-NEXT: lu12i.w $a1, -1
9-
; LA32-NEXT: and $a0, $a0, $a1
10-
; LA32-NEXT: lu12i.w $a1, 1
11-
; LA32-NEXT: xor $a0, $a0, $a1
8+
; LA32-NEXT: srli.w $a0, $a0, 12
9+
; LA32-NEXT: addi.w $a0, $a0, -1
1210
; LA32-NEXT: sltui $a0, $a0, 1
1311
; LA32-NEXT: ret
1412
;
1513
; LA64-LABEL: icmpimm:
1614
; LA64: # %bb.0:
17-
; LA64-NEXT: lu12i.w $a1, -1
18-
; LA64-NEXT: lu32i.d $a1, 0
19-
; LA64-NEXT: and $a0, $a0, $a1
20-
; LA64-NEXT: lu12i.w $a1, 1
21-
; LA64-NEXT: xor $a0, $a0, $a1
15+
; LA64-NEXT: bstrpick.d $a0, $a0, 31, 12
16+
; LA64-NEXT: addi.d $a0, $a0, -1
2217
; LA64-NEXT: sltui $a0, $a0, 1
2318
; LA64-NEXT: ret
2419
%1 = and i32 %x, -4096

0 commit comments

Comments
 (0)