Reland "[mips] Fix the target specific instruction verifier"

Fix an off by one error in the bounds checking for 'dinsu' and update
the ranges in the test comments so that they are accurate.

This version has the correct commit message.

Reviewers: atanasyan

Differential Revision: https://reviews.llvm.org/D41183

llvm-svn: 320991
diff --git a/llvm/lib/Target/Mips/MipsInstrInfo.cpp b/llvm/lib/Target/Mips/MipsInstrInfo.cpp
index 1bfd21c..51ddc0d 100644
--- a/llvm/lib/Target/Mips/MipsInstrInfo.cpp
+++ b/llvm/lib/Target/Mips/MipsInstrInfo.cpp
@@ -538,15 +538,19 @@
 }
 
 // ins, ext, dext*, dins have the following constraints:
-// 0 <= pos      <  X
-// 0 <  size     <= X
-// 0 <  pos+size <= x
+// X <= pos      <  Y
+// X <  size     <= Y
+// X <  pos+size <= Y
 //
-// dinsm and dinsm have the following contraints:
-// 0 <= pos      <  X
-// 0 <= size     <= X
-// 0 <  pos+size <= x
-
+// dinsm and dinsu have the following constraints:
+// X <= pos      <  Y
+// X <= size     <= Y
+// X <  pos+size <= Y
+//
+// The callee of verifyInsExtInstruction however gives the bounds of
+// dins[um] like the other (d)ins (d)ext(um) instructions, so that this
+// function doesn't have to vary it's behaviour based on the instruction
+// being checked.
 static bool verifyInsExtInstruction(const MachineInstr &MI, StringRef &ErrInfo,
                                     const int64_t PosLow, const int64_t PosHigh,
                                     const int64_t SizeLow,
@@ -595,15 +599,18 @@
     case Mips::DINS:
       return verifyInsExtInstruction(MI, ErrInfo, 0, 32, 0, 32, 0, 32);
     case Mips::DINSM:
-      // The ISA spec has a subtle difference here in that it says:
-      //  2 <= size <= 64 for 'dinsm', so we change the bounds so that it
-      // is in line with the rest of instructions.
+      // The ISA spec has a subtle difference difference between dinsm and dextm
+      // in that it says:
+      // 2 <= size <= 64 for 'dinsm' but 'dextm' has 32 < size <= 64.
+      // To make the bounds checks similar, the range 1 < size <= 64 is checked
+      // for 'dinsm'.
       return verifyInsExtInstruction(MI, ErrInfo, 0, 32, 1, 64, 32, 64);
     case Mips::DINSU:
-      // The ISA spec has a subtle difference here in that it says:
-      //  2 <= size <= 64 for 'dinsm', so we change the bounds so that it
-      // is in line with the rest of instructions.
-      return verifyInsExtInstruction(MI, ErrInfo, 32, 64, 1, 32, 32, 64);
+      // The ISA spec has a subtle difference between dinsu and dextu in that
+      // the size range of dinsu is specified as 1 <= size <= 32 whereas size
+      // for dextu is 0 < size <= 32. The range checked for dinsu here is
+      // 0 < size <= 32, which is equivalent and similar to dextu.
+      return verifyInsExtInstruction(MI, ErrInfo, 32, 64, 0, 32, 32, 64);
     case Mips::DEXT:
       return verifyInsExtInstruction(MI, ErrInfo, 0, 32, 0, 32, 0, 63);
     case Mips::DEXTM: