diff --git a/llvm/lib/Target/LoongArch/LoongArchISelLowering.h b/llvm/lib/Target/LoongArch/LoongArchISelLowering.h --- a/llvm/lib/Target/LoongArch/LoongArchISelLowering.h +++ b/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; diff --git a/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp b/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp --- a/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp +++ b/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); } diff --git a/llvm/test/CodeGen/LoongArch/legalicmpimm.ll b/llvm/test/CodeGen/LoongArch/legalicmpimm.ll --- a/llvm/test/CodeGen/LoongArch/legalicmpimm.ll +++ b/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