From: Kazu Hirata Date: Thu, 26 Jan 2023 04:44:53 +0000 (-0800) Subject: [Mips] Simplify isShiftedUIntAtAnyPosition (NFC) X-Git-Tag: upstream/17.0.6~19556 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3b53c6020052215be97898a4312fc41ca626a0ad;p=platform%2Fupstream%2Fllvm.git [Mips] Simplify isShiftedUIntAtAnyPosition (NFC) isShiftedUIntAtAnyPosition never gets zero as the argument because the caller processes ImmValue satisfying isInt<16>(ImmValue), which includes zero, long before it calls isShiftedUIntAtAnyPosition. Given that the argument is always nonzero, findFirstSet is identical to llvm::countr_zero. Also, x == x >> BitNum << BitNum is always true, so we are left with: isUInt(x >> llvm::countr_zero(x)) Just in case the caller changes its behavior and starts passing zero to us, we can protect the shift from undefined behavior "x << 64" by adding "x &&". --- diff --git a/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp b/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp index 45cbddd..bbfeec9 100644 --- a/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp +++ b/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp @@ -2671,9 +2671,7 @@ bool MipsAsmParser::expandJalWithRegs(MCInst &Inst, SMLoc IDLoc, /// Can the value be represented by a unsigned N-bit value and a shift left? template static bool isShiftedUIntAtAnyPosition(uint64_t x) { - unsigned BitNum = findFirstSet(x); - - return (x == x >> BitNum << BitNum) && isUInt(x >> BitNum); + return x && isUInt(x >> llvm::countr_zero(x)); } /// Load (or add) an immediate into a register.