Don't expand divisions by constants when attribute is minsize.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
This code in ReplaceNodeResults needs to call isIntDivCheap so that we promote div by constant when isIntDivCheap returns false. That will fix testsize2 and testsize4 to use divw and divuw for RV64IM.
case ISD::SDIV: case ISD::UDIV: case ISD::UREM: { MVT VT = N->getSimpleValueType(0); assert((VT == MVT::i8 || VT == MVT::i16 || VT == MVT::i32) && Subtarget.is64Bit() && Subtarget.hasStdExtM() && "Unexpected custom legalisation"); // Don't promote division/remainder by constant since we should expand those // to multiply by magic constant. // FIXME: What if the expansion is disabled for minsize. if (N->getOperand(1).getOpcode() == ISD::Constant) return;
llvm/lib/Target/RISCV/RISCVISelLowering.cpp | ||
---|---|---|
12541 | There is MF->getFunction().hasOptSize() which also checks for Attribute::OptimizeForSize. |
llvm/lib/Target/RISCV/RISCVISelLowering.cpp | ||
---|---|---|
12541 | Every other target that does this only does it for MinSize. Are you suggesting we do this for -Os as well? |
llvm/lib/Target/RISCV/RISCVISelLowering.cpp | ||
---|---|---|
12541 | That's right. |
llvm/lib/Target/RISCV/RISCVISelLowering.cpp | ||
---|---|---|
12541 | Please ignore my comment, I mixed up OptimizeForSize and MinSize. Returning false only for MinSize sounds reasonable. |
llvm/lib/Target/RISCV/RISCVISelLowering.cpp | ||
---|---|---|
12540 | The reason why other targets make vector an exception is because there is no vector integer division as the comments said, so I think it is OK for RVV since there are vector integer divide instructions. While for P extension, it could be an exception. |
llvm/lib/Target/RISCV/RISCVISelLowering.cpp | ||
---|---|---|
12540 | Yes, that is why I added a TODO. |
The reason why other targets make vector an exception is because there is no vector integer division as the comments said, so I think it is OK for RVV since there are vector integer divide instructions. While for P extension, it could be an exception.