GlobalISel: Verify memory size for load/store
llvm-svn: 352578
diff --git a/llvm/lib/CodeGen/MachineVerifier.cpp b/llvm/lib/CodeGen/MachineVerifier.cpp
index fb15c17..761c4e6 100644
--- a/llvm/lib/CodeGen/MachineVerifier.cpp
+++ b/llvm/lib/CodeGen/MachineVerifier.cpp
@@ -1004,6 +1004,7 @@
case TargetOpcode::G_STORE:
case TargetOpcode::G_ZEXTLOAD:
case TargetOpcode::G_SEXTLOAD: {
+ LLT ValTy = MRI->getType(MI->getOperand(0).getReg());
LLT PtrTy = MRI->getType(MI->getOperand(1).getReg());
if (!PtrTy.isPointer())
report("Generic memory instruction must access a pointer", MI);
@@ -1014,13 +1015,17 @@
report("Generic instruction accessing memory must have one mem operand",
MI);
} else {
+ const MachineMemOperand &MMO = **MI->memoperands_begin();
if (MI->getOpcode() == TargetOpcode::G_ZEXTLOAD ||
MI->getOpcode() == TargetOpcode::G_SEXTLOAD) {
- const MachineMemOperand &MMO = **MI->memoperands_begin();
- LLT DstTy = MRI->getType(MI->getOperand(0).getReg());
- if (MMO.getSize() * 8 >= DstTy.getSizeInBits()) {
+ if (MMO.getSize() * 8 >= ValTy.getSizeInBits())
report("Generic extload must have a narrower memory type", MI);
- }
+ } else if (MI->getOpcode() == TargetOpcode::G_LOAD) {
+ if (MMO.getSize() > (ValTy.getSizeInBits() + 7) / 8)
+ report("load memory size cannot exceed result size", MI);
+ } else if (MI->getOpcode() == TargetOpcode::G_STORE) {
+ if ((ValTy.getSizeInBits() + 7) / 8 < MMO.getSize())
+ report("store memory size cannot exceed value size", MI);
}
}