Removing the first instruction in the base unit from LLVM IR?

I have the following LLRM IRL file

  %1 = load i32* %i, align 4
  %2 = load i32* %j, align 4
  %3 = icmp sgt i32 %1, %2
  br i1 %3, label %4, label %6

; <label>:4                                       ; preds = %0
  %5 = load i32* %i, align 4
  store i32 %5, i32* %k, align 4
  br label %6

; <label>:6                                       ; preds = %5, %0
  ret i32 0

In it, I first load the vairable "i" in% 1 and the variable "j" in% 2, then I compare a larger condition than (i> j). Based on this, there is a branch to either label 4 or label 6. My problem is that there are two load commands for the variable "i" in the first base unit and in another base unit. Here I want to delete the second boot statement. To do this, I do this as when I get to the second load instruction for the variable "i". I replace all uses of the second command with the first instruction, then I erase the current instruction, that is, the second. Here I cannot set the pointer of the iterator of instructions. I do not want to install the following command (store i32% 5, i32 *% k, align 4). Is there another way? If you know, please let me know.

+5
1

, , , . , DeadInstElimintation ( lib/Transforms/Scalar/DCE.cpp):

virtual bool runOnBasicBlock(BasicBlock &BB) {
  bool Changed = false;
  for (BasicBlock::iterator DI = BB.begin(); DI != BB.end(); ) {
    Instruction *Inst = DI++;
    if (isInstructionTriviallyDead(Inst)) {
      Inst->eraseFromParent();
      Changed = true;
      ++DIEEliminated;
    }
  }
  return Changed;
}

, . DI++ for, , DI, Inst. , Inst, DI , .

+10

All Articles