[PATCH] D117465: [RISCV] Add patterns to MIR sign-extension removal pass.
Mohammed Nurul Hoque via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 17 04:09:39 PST 2022
mohammed-nurulhoque created this revision.
mohammed-nurulhoque added reviewers: asb, craig.topper, kito-cheng.
mohammed-nurulhoque added a project: LLVM.
Herald added subscribers: VincentWu, luke957, achieveartificialintelligence, vkmr, frasercrmck, evandro, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, niosHD, sabuasal, simoncook, johnrusso, rbar, hiraditya.
mohammed-nurulhoque requested review of this revision.
Herald added subscribers: llvm-commits, alextsao1999, eopXD, MaskRay.
This patch adds a few instruction patterns that generate sign-extended values or propagate them, adding to the pass introduced in https://reviews.llvm.org/D116397
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D117465
Files:
llvm/lib/Target/RISCV/RISCVSExtWRemoval.cpp
Index: llvm/lib/Target/RISCV/RISCVSExtWRemoval.cpp
===================================================================
--- llvm/lib/Target/RISCV/RISCVSExtWRemoval.cpp
+++ llvm/lib/Target/RISCV/RISCVSExtWRemoval.cpp
@@ -95,10 +95,24 @@
case RISCV::LHU:
case RISCV::LB:
case RISCV::LH:
+ case RISCV::SLT:
+ case RISCV::SLTI:
+ case RISCV::SLTU:
+ case RISCV::SLTIU:
case RISCV::SEXTB:
case RISCV::SEXTH:
case RISCV::ZEXTH_RV64:
return true;
+ // shifting right sufficiently makes the value 32-bit sign-extended
+ case RISCV::SRAI:
+ return MI.getOperand(2).getImm() >= 32;
+ case RISCV::SRLI:
+ return MI.getOperand(2).getImm() > 32;
+ // mask sets or resets bits 63:31
+ case RISCV::ANDI:
+ return countLeadingZeros((uint64_t)MI.getOperand(2).getImm()) > 32;
+ case RISCV::ORI:
+ return countLeadingOnes((uint64_t)MI.getOperand(2).getImm()) > 32;
}
// The LI pattern ADDI rd, X0, imm is sign extended.
@@ -157,9 +171,15 @@
Worklist.push_back(SrcMI);
break;
}
+ case RISCV::DIVU:
+ case RISCV::REM:
+ case RISCV::REMU:
case RISCV::ANDI:
case RISCV::ORI:
case RISCV::XORI: {
+ // |Quotient| and |Remainder| are always <= |Dividend|. If D fits in
+ // 32-bit, then so do Q & R. Sign-division doesn't work because of
+ // the edge case (long)0x8000 0000 / (long)-1
// Logical operations use a sign extended 12-bit immediate. We just need
// to check if the other operand is sign extended.
Register SrcReg = MI->getOperand(1).getReg();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D117465.400487.patch
Type: text/x-patch
Size: 1562 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220117/a804de4c/attachment.bin>
More information about the llvm-commits
mailing list