summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Target/Mips/MipsSERegisterInfo.cpp
diff options
context:
space:
mode:
authorDaniel Sanders <daniel.sanders@imgtec.com>2013-12-09 12:47:12 +0000
committerDaniel Sanders <daniel.sanders@imgtec.com>2013-12-09 12:47:12 +0000
commit3519dce968d307ee9fedca7c25ff6624549fd185 (patch)
treef6bf73ef559f9cebade63483065577cbb660e938 /llvm/lib/Target/Mips/MipsSERegisterInfo.cpp
parentcfea74944a3158b3caab91f7ca6b741a42637738 (diff)
downloadbcm5719-llvm-3519dce968d307ee9fedca7c25ff6624549fd185.tar.gz
bcm5719-llvm-3519dce968d307ee9fedca7c25ff6624549fd185.zip
[mips][msa] Fix invalid generated code when lowering FrameIndex involving unaligned offsets.
Summary: The MSA ld.[bhwd] and st.[bhwd] instructions scale the immediate by the element size before use as an offset. The offset must therefore be a multiple of the element size to be valid in these instructions. However, an unaligned base address is valid in MSA. This commit causes the compiler to emit valid code when the calculated offset is not a multiple of the element size by accounting for the offset using addiu and using a zero offset in the load/store. Depends on D2338 Reviewers: matheusalmeida Reviewed By: matheusalmeida Differential Revision: http://llvm-reviews.chandlerc.com/D2339 llvm-svn: 196777
Diffstat (limited to 'llvm/lib/Target/Mips/MipsSERegisterInfo.cpp')
-rw-r--r--llvm/lib/Target/Mips/MipsSERegisterInfo.cpp23
1 files changed, 21 insertions, 2 deletions
diff --git a/llvm/lib/Target/Mips/MipsSERegisterInfo.cpp b/llvm/lib/Target/Mips/MipsSERegisterInfo.cpp
index cf408a1c098..fcf6d0b06c7 100644
--- a/llvm/lib/Target/Mips/MipsSERegisterInfo.cpp
+++ b/llvm/lib/Target/Mips/MipsSERegisterInfo.cpp
@@ -84,6 +84,23 @@ static inline unsigned getLoadStoreOffsetSizeInBits(const unsigned Opcode) {
}
}
+/// Get the scale factor applied to the immediate in the given load/store.
+static inline unsigned getLoadStoreOffsetAlign(const unsigned Opcode) {
+ switch (Opcode) {
+ case Mips::LD_H:
+ case Mips::ST_H:
+ return 2;
+ case Mips::LD_W:
+ case Mips::ST_W:
+ return 4;
+ case Mips::LD_D:
+ case Mips::ST_D:
+ return 8;
+ default:
+ return 1;
+ }
+}
+
void MipsSERegisterInfo::eliminateFI(MachineBasicBlock::iterator II,
unsigned OpNo, int FrameIndex,
uint64_t StackSize,
@@ -138,9 +155,11 @@ void MipsSERegisterInfo::eliminateFI(MachineBasicBlock::iterator II,
// For MSA instructions, this is a 10-bit signed immediate (scaled by
// element size), otherwise it is a 16-bit signed immediate.
unsigned OffsetBitSize = getLoadStoreOffsetSizeInBits(MI.getOpcode());
+ unsigned OffsetAlign = getLoadStoreOffsetAlign(MI.getOpcode());
- if (OffsetBitSize < 16 && !isIntN(OffsetBitSize, Offset) &&
- isInt<16>(Offset)) {
+ if (OffsetBitSize < 16 && isInt<16>(Offset) &&
+ (!isIntN(OffsetBitSize, Offset) ||
+ OffsetToAlignment(Offset, OffsetAlign) != 0)) {
// If we have an offset that needs to fit into a signed n-bit immediate
// (where n < 16) and doesn't, but does fit into 16-bits then use an ADDiu
MachineBasicBlock &MBB = *MI.getParent();
OpenPOWER on IntegriCloud