guilhermeleobas / phoenix

optimize arithmetic instructions that accepts an identity
5 stars 4 forks source link

A possible bug about casting branch condition #1

Open BowenZhang-UST opened 1 year ago

BowenZhang-UST commented 1 year ago

Commit

Lattest Main

Location

Description

The code at ProgramSlicing/ProgramSlicing.cpp Line 419 tries to cast the condition of an conditional branch into Instruction. However, the condition of BranchInst is not always Instruction. When the condition is an Argument, there would be a cast exception.

image

The code at DAG/inter_profile.cpp Line 487 is similar.

image

Proposed Fix

Turn the cast into a dynamic cast, and use an if-check to guard it.

    // Only for predicates that are defined in a different basic block
-  auto *pred = cast<Instruction>(br->getCondition());
+ if (auto *pred=dyn_cast<Instruction>(br->getCondition())) {
    if (pred->getParent() == &BB)
      continue; 
+ }
guilhermeleobas commented 1 year ago

Hi @BowenZhang-UST, thanks for the report. As for a more updated implementation, check https://github.com/lac-dcc/wyvern/tree/master/passes

BowenZhang-UST commented 1 year ago

Thank you for reviewing this issue and providing an updated implementation! @guilhermeleobas