[llvm] [RISCV] Disable constant hoisting for mul by one more/less than a pow… (PR #67385)

Wang Pengcheng via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 25 20:25:02 PDT 2023


================
@@ -127,6 +127,9 @@ InstructionCost RISCVTTIImpl::getIntImmCostInst(unsigned Opcode, unsigned Idx,
     // Power of 2 is a shift. Negated power of 2 is a shift and a negate.
     if (Imm.isPowerOf2() || Imm.isNegatedPowerOf2())
       return TTI::TCC_Free;
+    // One more or less than a power of 2 can use SLLI+ADD/SUB.
+    if ((Imm + 1).isPowerOf2() || (Imm - 1).isPowerOf2())
----------------
wangpc-pp wrote:

What about negative values? It needs 3 instructions I think, would it be worthy too?

https://github.com/llvm/llvm-project/pull/67385


More information about the llvm-commits mailing list