File tree 2 files changed +18
-0
lines changed
2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -768,6 +768,9 @@ void GenericCXXCodeGen::RunOnFunction(Function& function) {
768
768
void GenericCXXCodeGen::RunOnConstant (Constant& constant, bool decl) {
769
769
const auto & uses = constant.GetIthResultUses (0 );
770
770
bool only_used_by_reshape = true ;
771
+ if (uses.empty ()) {
772
+ return ;
773
+ }
771
774
for (const auto & u : uses) {
772
775
if (!IsA<Instruction>(u.GetUse ()) ||
773
776
DynCast<Instruction>(u.GetUse ())->GetOpCode () != OpCode::RESHAPE ||
Original file line number Diff line number Diff line change 24
24
25
25
namespace halo {
26
26
27
+ static void RemoveLoopBody (LoopInst* loop_inst) {
28
+ auto body = loop_inst->GetBody ();
29
+ auto return_inst = body->GetReturnInst ();
30
+ if (return_inst != nullptr ) {
31
+ // Drop all the operands of the return instruction so the rest of the body
32
+ // loop will be DCE'ed automatically.
33
+ // Note that the return inst cannot be erased because the current legalizer
34
+ // will try to append one if no return inst exists for a block.
35
+ return_inst->DropAllOperands ();
36
+ }
37
+ }
38
+
27
39
bool DCE::RunOnBasicBlock (BasicBlock* bb) {
28
40
bool changed = false ;
29
41
std::set<Instruction*> dead_instrs;
@@ -42,6 +54,9 @@ bool DCE::RunOnBasicBlock(BasicBlock* bb) {
42
54
for (auto it = bb->begin (), e = bb->end (); it != e;) {
43
55
Instruction* inst = it->get ();
44
56
if (dead_instrs.count (inst) > 0 ) {
57
+ if (inst->GetOpCode () == OpCode::LOOP) {
58
+ RemoveLoopBody (DynCast<LoopInst>(inst));
59
+ }
45
60
it = bb->Instructions ().erase (it);
46
61
} else {
47
62
it = std::next (it);
You can’t perform that action at this time.
0 commit comments