DCEInst kill the same instruction twice.
authorSteven Perron <stevenperron@google.com>
Mon, 4 Dec 2017 17:29:51 +0000 (12:29 -0500)
committerSteven Perron <stevenperron@google.com>
Mon, 4 Dec 2017 23:15:35 +0000 (18:15 -0500)
In DCEInst, it is possible that the same instruction ends up in the
queue multiple times, if the same id is used multiple times in the
same instruction.

The solution is to keep the ids in a set, to ensure no duplication in
the list.

source/opt/mem_pass.cpp

index 0d39a4f..2a815d7 100644 (file)
@@ -184,7 +184,7 @@ void MemPass::AddStores(uint32_t ptr_id, std::queue<ir::Instruction*>* insts) {
 }
 
 void MemPass::DCEInst(ir::Instruction* inst,
-                      const function<void(ir::Instruction * )>& call_back) {
+                      const function<void(ir::Instruction*)>& call_back) {
   std::queue<ir::Instruction*> deadInsts;
   deadInsts.push(inst);
   while (!deadInsts.empty()) {
@@ -195,8 +195,8 @@ void MemPass::DCEInst(ir::Instruction* inst,
       continue;
     }
     // Remember operands
-    std::vector<uint32_t> ids;
-    di->ForEachInId([&ids](uint32_t* iid) { ids.push_back(*iid); });
+    std::set<uint32_t> ids;
+    di->ForEachInId([&ids](uint32_t* iid) { ids.insert(*iid); });
     uint32_t varId = 0;
     // Remember variable if dead load
     if (di->opcode() == SpvOpLoad) (void)GetPtr(di, &varId);