GBE: fix a regression for piglit test.
authorZhigang Gong <zhigang.gong@intel.com>
Wed, 28 May 2014 09:02:16 +0000 (17:02 +0800)
committerZhigang Gong <zhigang.gong@intel.com>
Thu, 29 May 2014 06:46:52 +0000 (14:46 +0800)
Access this->store[insnID+2] is not always safe, as it may
not exist.

Signed-off-by: Zhigang Gong <zhigang.gong@intel.com>
Reviewed-by: "Yang, Rong R" <rong.r.yang@intel.com>
backend/src/backend/gen_encoder.cpp

index 038d14b..0091e81 100644 (file)
@@ -1101,7 +1101,6 @@ namespace gbe
 
   void GenEncoder::patchJMPI(uint32_t insnID, int32_t jumpDistance) {
     GenNativeInstruction &insn = *(GenNativeInstruction *)&this->store[insnID];
-    GenNativeInstruction &insn2 = *(GenNativeInstruction *)&this->store[insnID+2];
     GBE_ASSERT(insnID < this->store.size());
     GBE_ASSERT(insn.header.opcode == GEN_OPCODE_JMPI ||
                insn.header.opcode == GEN_OPCODE_BRD  ||
@@ -1130,12 +1129,15 @@ namespace gbe
       // for all the branching instruction. And need to adjust the distance
       // for those branch instruction's start point and end point contains
       // this instruction.
-      GBE_ASSERT(insn2.header.opcode == GEN_OPCODE_NOP);
+      GenNativeInstruction *insn2 = (GenNativeInstruction *)&this->store[insnID+2];
+      GBE_ASSERT(insn2->header.opcode == GEN_OPCODE_NOP);
+      insn2 = insn2;
       insn.header.opcode = GEN_OPCODE_ADD;
       this->setDst(&insn, GenRegister::ip());
       this->setSrc0(&insn, GenRegister::ip());
       this->setSrc1(&insn, GenRegister::immd(jumpDistance * 8));
     } else {
+      GenNativeInstruction &insn2 = *(GenNativeInstruction *)&this->store[insnID+2];
       insn.header.predicate_inverse ^= 1;
       this->setSrc1(&insn, GenRegister::immd(2));
       GBE_ASSERT(insn2.header.opcode == GEN_OPCODE_NOP);