Reland "[mips] Fix the target specific instruction verifier"
authorSimon Dardis <simon.dardis@mips.com>
Mon, 18 Dec 2017 15:56:40 +0000 (15:56 +0000)
committerSimon Dardis <simon.dardis@mips.com>
Mon, 18 Dec 2017 15:56:40 +0000 (15:56 +0000)
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

27 files changed:
llvm/lib/Target/Mips/MipsInstrInfo.cpp
llvm/test/CodeGen/Mips/fcopysign-f32-f64.ll
llvm/test/CodeGen/Mips/fcopysign.ll
llvm/test/CodeGen/Mips/instverify/dext-pos.mir
llvm/test/CodeGen/Mips/instverify/dext-size.mir
llvm/test/CodeGen/Mips/instverify/dextm-pos-size.mir
llvm/test/CodeGen/Mips/instverify/dextm-pos.mir
llvm/test/CodeGen/Mips/instverify/dextm-size.mir
llvm/test/CodeGen/Mips/instverify/dextu-pos-size.mir
llvm/test/CodeGen/Mips/instverify/dextu-pos.mir
llvm/test/CodeGen/Mips/instverify/dextu-size-valid.mir [new file with mode: 0644]
llvm/test/CodeGen/Mips/instverify/dextu-size.mir
llvm/test/CodeGen/Mips/instverify/dins-pos-size.mir
llvm/test/CodeGen/Mips/instverify/dins-pos.mir
llvm/test/CodeGen/Mips/instverify/dins-size.mir
llvm/test/CodeGen/Mips/instverify/dinsm-pos-size.mir
llvm/test/CodeGen/Mips/instverify/dinsm-pos.mir
llvm/test/CodeGen/Mips/instverify/dinsm-size.mir
llvm/test/CodeGen/Mips/instverify/dinsu-pos-size.mir
llvm/test/CodeGen/Mips/instverify/dinsu-pos.mir
llvm/test/CodeGen/Mips/instverify/dinsu-size.mir
llvm/test/CodeGen/Mips/instverify/ext-pos-size.mir
llvm/test/CodeGen/Mips/instverify/ext-pos.mir
llvm/test/CodeGen/Mips/instverify/ext-size.mir
llvm/test/CodeGen/Mips/instverify/ins-pos-size.mir
llvm/test/CodeGen/Mips/instverify/ins-pos.mir
llvm/test/CodeGen/Mips/instverify/ins-size.mir

index 1bfd21c02db63323c19251cfdad58b5a76567cb2..51ddc0d44c0022cb95750441148560bd0f981385 100644 (file)
@@ -538,15 +538,19 @@ bool MipsInstrInfo::findCommutedOpIndices(MachineInstr &MI, unsigned &SrcOpIdx1,
 }
 
 // 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 @@ bool MipsInstrInfo::verifyInstruction(const MachineInstr &MI,
     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:
index 9ec2b8e2425a4243f7a61133f1f795c0a5f61b99..695431a5ab6074c679957da892c90ea01c558b60 100644 (file)
@@ -1,9 +1,9 @@
-; RUN: llc  < %s -march=mips64el -mcpu=mips4 -target-abi=n64 | \
-; RUN:    FileCheck %s -check-prefixes=ALL,64
-; RUN: llc  < %s -march=mips64el -mcpu=mips64 -target-abi=n64 | \
-; RUN:    FileCheck %s -check-prefixes=ALL,64
-; RUN: llc  < %s -march=mips64el -mcpu=mips64r2 -target-abi=n64 | \
-; RUN:    FileCheck %s -check-prefixes=ALL,64R2
+; RUN: llc  < %s -verify-machineinstrs -march=mips64el -mcpu=mips4 \
+; RUN:   -target-abi=n64 | FileCheck %s -check-prefixes=ALL,64
+; RUN: llc  < %s -verify-machineinstrs -march=mips64el -mcpu=mips64 \
+; RUN:   -target-abi=n64 | FileCheck %s -check-prefixes=ALL,64
+; RUN: llc  < %s -verify-machineinstrs -march=mips64el -mcpu=mips64r2 \
+; RUN:   -target-abi=n64 | FileCheck %s -check-prefixes=ALL,64R2
 
 declare double @copysign(double, double) nounwind readnone
 
index 9be876f2a9b306ed178e4c749388644f3d002da3..810d0f9580861cf8333ec2de438d81959b93bce1 100644 (file)
@@ -1,8 +1,13 @@
-; RUN: llc  < %s -march=mipsel -mcpu=mips32 | FileCheck %s -check-prefix=32
-; RUN: llc  < %s -march=mipsel -mcpu=mips32r2 | FileCheck %s -check-prefix=32R2
-; RUN: llc  < %s -march=mips64el -mcpu=mips4 -target-abi=n64 | FileCheck %s -check-prefix=64
-; RUN: llc  < %s -march=mips64el -mcpu=mips64 -target-abi=n64 | FileCheck %s -check-prefix=64
-; RUN: llc  < %s -march=mips64el -mcpu=mips64r2 -target-abi=n64 | FileCheck %s -check-prefix=64R2
+; RUN: llc  < %s -verify-machineinstrs -march=mipsel -mcpu=mips32 \
+; RUN:   | FileCheck %s -check-prefix=32
+; RUN: llc  < %s -verify-machineinstrs -march=mipsel -mcpu=mips32r2 \
+; RUN:   | FileCheck %s -check-prefix=32R2
+; RUN: llc  < %s -verify-machineinstrs -march=mips64el -mcpu=mips4 -target-abi=n64 \
+; RUN:   | FileCheck %s -check-prefix=64
+; RUN: llc  < %s -verify-machineinstrs -march=mips64el -mcpu=mips64 -target-abi=n64 \
+; RUN:   | FileCheck %s -check-prefix=64
+; RUN: llc  < %s -verify-machineinstrs -march=mips64el -mcpu=mips64r2 -target-abi=n64 \
+; RUN:   | FileCheck %s -check-prefix=64R2
 
 define double @func0(double %d0, double %d1) nounwind readnone {
 entry:
index 5b57564df705bfe23872c84e33063c226d4489a0..8e3b887ffe9e1b24fb98ff742e604972bb9b405d 100644 (file)
@@ -3,7 +3,7 @@
 
 # CHECK: Position operand is out of range!
 
-# Check that the machine verifier checks the position operand is in range 0..31
+# Check that the machine verifier checks the position operand is in the range 0..31
 ---
 name:            dext
 alignment:       3
index d6436108cefd461fe6a0ebce73377aa291fbb648..968dd4e370fd1fc9e0ac21522dd0a2fda0cbdfff 100644 (file)
@@ -3,7 +3,7 @@
 
 # CHECK: Size operand is out of range!
 
-# Check that the machine verifier checks the size operand is in range 0..32
+# Check that the machine verifier checks the size operand is in the range 1..32
 ---
 name:            dext
 alignment:       3
index eec459fef42e9f6b15f8fb3fac515f2ca6fbde03..bdf82ecd0d675d0af6bf96d3476c1ec489ae4593 100644 (file)
@@ -3,7 +3,7 @@
 
 # CHECK: Position + Size is out of range!
 
-# Check that the machine verifier checks the pos + size is in range 32..64
+# Check that the machine verifier checks the pos + size is in the range 33..64
 ---
 name:            dextm
 alignment:       3
index 782d3fb8b653360215f7f4884d141e932b6aa285..987a228a1f8ead055e1c78a38bf82001f7c6c284 100644 (file)
@@ -3,7 +3,7 @@
 
 # CHECK: Position operand is out of range!
 
-# Check that the machine verifier checks the position operand is in range 0..31
+# Check that the machine verifier checks the position operand is in the range 0..31
 ---
 name:            dextm
 alignment:       3
index 771abef6517e2d11e7775bb58178b6d3ad099fdb..b1e367e027e37d2aad47b3ecddf67fb2469544bd 100644 (file)
@@ -3,7 +3,7 @@
 
 # CHECK: Size operand is out of range!
 
-# Check that the machine verifier checks the size operand is in range 32..64
+# Check that the machine verifier checks the size operand is in the range 33..64
 ---
 name:            dextm
 alignment:       3
index 5356cf5dfc1c518efdcfd059796db8823041b008..9b6dac08350053dace0cb59b0f228c8bfe2bb5a0 100644 (file)
@@ -3,7 +3,7 @@
 
 # CHECK: Position + Size is out of range!
 
-# Check that the machine verifier checks the pos + size is in range 32..64
+# Check that the machine verifier checks the pos + size is in the range 33..64
 ---
 name:            dextu
 alignment:       3
index 11b94c3fd8d3e33b459fd5a537b97bd67aa8e8d0..65e5bd0e1c1e35108af00be117c0f68b9d1b612b 100644 (file)
@@ -3,7 +3,7 @@
 
 # CHECK: Position operand is out of range!
 
-# Check that the machine verifier checks the position operand is in range 32..63
+# Check that the machine verifier checks the position operand is in the range 32..63
 ---
 name:            dextu
 alignment:       3
@@ -42,7 +42,7 @@ body:             |
     liveins: %a0_64
 
     %0 = COPY %a0_64
-    %1 = DEXTU %0, 65, 5
+    %1 = DEXTU %0, 64, 5
     %v0_64 = COPY %1
     RetRA implicit %v0_64
 
diff --git a/llvm/test/CodeGen/Mips/instverify/dextu-size-valid.mir b/llvm/test/CodeGen/Mips/instverify/dextu-size-valid.mir
new file mode 100644 (file)
index 0000000..8c548f1
--- /dev/null
@@ -0,0 +1,49 @@
+# RUN: llc -march=mips64 -mcpu=mips64r2 -start-after=expand-isel-pseudos -stop-after=expand-isel-pseudos \
+# RUN:     -verify-machineinstrs %s -o - 2>&1 | FileCheck %s
+
+# CHECK-NOT: Size operand is out of range!
+
+# Check that the machine verifier checks the size operand is in the range 1..32
+---
+name:            dextu
+alignment:       3
+exposesReturnsTwice: false
+legalized:       false
+regBankSelected: false
+selected:        false
+tracksRegLiveness: true
+registers:
+  - { id: 0, class: gpr64, preferred-register: '' }
+  - { id: 1, class: gpr64, preferred-register: '' }
+liveins:
+  - { reg: '%a0_64', virtual-reg: '%0' }
+frameInfo:
+  isFrameAddressTaken: false
+  isReturnAddressTaken: false
+  hasStackMap:     false
+  hasPatchPoint:   false
+  stackSize:       0
+  offsetAdjustment: 0
+  maxAlignment:    1
+  adjustsStack:    false
+  hasCalls:        false
+  stackProtector:  ''
+  maxCallFrameSize: 4294967295
+  hasOpaqueSPAdjustment: false
+  hasVAStart:      false
+  hasMustTailInVarArgFunc: false
+  savePoint:       ''
+  restorePoint:    ''
+fixedStack:
+stack:
+constants:
+body:             |
+  bb.0.entry:
+    liveins: %a0_64
+
+    %0 = COPY %a0_64
+    %1 = DEXTU %0, 63, 1
+    %v0_64 = COPY %1
+    RetRA implicit %v0_64
+
+...
index 4efdd966f7b54ee325ba7c0e18528d7b4896e8eb..0511d1ae09dc083035a03dad4a8f79e88762c600 100644 (file)
@@ -3,7 +3,7 @@
 
 # CHECK: Size operand is out of range!
 
-# Check that the machine verifier checks the size operand is in range 0..32
+# Check that the machine verifier checks the size operand is in the range 1..32
 ---
 name:            dextu
 alignment:       3
index 6276790edc5fbc8b5452875b87c01d1b74f2ba1a..d1d178575c8f2006ec9c96dd6fc2a90ba35b41e9 100644 (file)
@@ -3,7 +3,7 @@
 
 # CHECK: Position + Size is out of range!
 
-# Check that the machine verifier checks the pos + size  is in range 0..32
+# Check that the machine verifier checks the pos + size is in the range 1..32
 ---
 name:            dins
 alignment:       3
index fe61deaebf04dce24aba841361561438d73da0a3..1602aa2e25adb1480d79182ca8701bd133c7845e 100644 (file)
@@ -3,7 +3,7 @@
 
 # CHECK: Position operand is out of range!
 
-# Check that the machine verifier checks the position operand is in range 0..31
+# Check that the machine verifier checks the position operand is in the range 0..31
 ---
 name:            dins
 alignment:       3
index 9fa0bc79a4bc4ae0ea917e5adc13efa4dc3fbccb..bf713bf992f3f7d2fe6aec3993d77570876dad06 100644 (file)
@@ -3,7 +3,7 @@
 
 # CHECK: Size operand is out of range!
 
-# Check that the machine verifier checks the size operand is in range 0..32
+# Check that the machine verifier checks the size operand is in the range 1..32
 ---
 name:            dins
 alignment:       3
index 450aa6a50539c0f7d1ac38d17c283aeac0ca45c9..aa73e7f1a53b69eece3e9229aac32ca096e87e65 100644 (file)
@@ -3,7 +3,7 @@
 
 # CHECK: Position + Size is out of range!
 
-# Check that the machine verifier checks the pos + size is in range 32..64
+# Check that the machine verifier checks the pos + size is in the range 33..64
 ---
 name:            dinsu
 alignment:       3
index 75bf00edd9616b6ae2eb9db58210b8f3c7040bca..66a6053ca74f2143fdb3a05a928cd87bde1497c7 100644 (file)
@@ -3,7 +3,7 @@
 
 # CHECK: Position operand is out of range!
 
-# Check that the machine verifier checks the position operand is in range 0..31
+# Check that the machine verifier checks the position operand is in the range 0..31
 ---
 name:            dinsm
 alignment:       3
index 9b501d44c47d5ff0333697a019f33afe645c6ae8..fba3bee969a6dc415ee565de5aaa22d5839fca59 100644 (file)
@@ -3,7 +3,7 @@
 
 # CHECK: Size operand is out of range!
 
-# Check that the machine verifier checks the size operand is in range 2..64
+# Check that the machine verifier checks the size operand is in the range 2..64
 ---
 name:            dinsm
 alignment:       3
index 51a53041504b3bd2eee56318a55efae62a23dece..9d2d17c3c18f3dc5e351cf98fac0139f8e411489 100644 (file)
@@ -3,7 +3,7 @@
 
 # CHECK: Position + Size is out of range!
 
-# Check that the machine verifier checks the pos + size is in range 32..64
+# Check that the machine verifier checks the pos + size is in the range 33..64
 ---
 name:            dinsu
 alignment:       3
index cbfae688b0a97225a407afb40ff146dc6ded32a2..d89bb2de3aea6b598ad1f347943d66405a6b8175 100644 (file)
@@ -3,7 +3,7 @@
 
 # CHECK: Position operand is out of range!
 
-# Check that the machine verifier checks the position operand is in range 32..63
+# Check that the machine verifier checks the position operand is in the range 32..63
 ---
 name:            dinsu
 alignment:       3
index 048a6f01c800f1d35f3d044e31971505770c0662..550f890fbd8ecb6636d9a89765060540f5ae2d69 100644 (file)
@@ -3,7 +3,7 @@
 
 # CHECK: Size operand is out of range!
 
-# Check that the machine verifier checks the size operand is in range 0..32
+# Check that the machine verifier checks the size operand is in the range 1..32
 ---
 name:            dinsu
 alignment:       3
index c230331e8ef6332942942a9ef770c297b2c1063e..94edecd8d24a1d667e77464b8bc9bf9d803870cf 100644 (file)
@@ -3,7 +3,7 @@
 
 # CHECK: Position + Size is out of range!
 
-# Check that the machine verifier checks the pos + size  is in range 0..32
+# Check that the machine verifier checks the pos + size is in the range 1..32
 ---
 name:            f
 alignment:       2
index ce472db2ef0b1e27fdb9f81fadd4152c9778bbc8..7cca1b6a1b3d9589f8026774410a0e06f6552519 100644 (file)
@@ -3,7 +3,7 @@
 
 # CHECK: Position operand is out of range!
 
-# Check that the machine verifier checks the position operand is in range 0..31
+# Check that the machine verifier checks the position operand is in the range 0..31
 ---
 name:            f
 alignment:       2
index 00f7182df4a894bd3cadde2b5ccca8b6a1bd2233..4c35e1fb6a0959d3239bee60dfbc0684bdcc8c44 100644 (file)
@@ -3,7 +3,7 @@
 
 # CHECK: Size operand is out of range!
 
-# Check that the machine verifier checks the size operand is in range 0..32
+# Check that the machine verifier checks the size operand is in the range 1..32
 ---
 name:            f
 alignment:       2
index 95872364e07188172e3830e4ae8a62c58b315758..e825b5997d8b9726dc03da28900fa8cc0d0c6e6b 100644 (file)
@@ -3,7 +3,7 @@
 
 # CHECK: Position + Size is out of range!
 
-# Check that the machine verifier checks the pos + size  is in range 0..32
+# Check that the machine verifier checks the pos + size is in the range 1..32
 ---
 name:            f
 alignment:       2
index c8811ed3e20e64565d6a45a4b55bc49748449b98..a284fdb5799896cb710b67811cd18b0736faa106 100644 (file)
@@ -3,7 +3,7 @@
 
 # CHECK: Position operand is out of range!
 
-# Check that the machine verifier checks the position operand is in range 0..31
+# Check that the machine verifier checks the position operand is in the range 0..31
 ---
 name:            f
 alignment:       2
index fba25212e1a4e05e753d5fa4be9d9912568a43c5..6cd839a01c6b491790ca6136320dcc4778a51b2a 100644 (file)
@@ -3,7 +3,7 @@
 
 # CHECK: Size operand is out of range!
 
-# Check that the machine verifier checks the size operand is in range 0..32
+# Check that the machine verifier checks the size operand is in the range 1..32
 ---
 name:            f
 alignment:       2