phi指令并不支配所有用途

时间:2015-04-19 21:11:07

标签: llvm llvm-ir

我有llvm-IR功能 当我尝试将其转换为.bc时,llvm-as显示出很多错误。 例如:

Instruction does not dominate all uses!
     %rightBoundary.1.i = phi i32 [ %dec.i, %while.cond1.i ], [ %rightBoundary.046.i, %while.cond1.preheader.i ]
      %rightBoundary.046.i = phi i32 [ %rightBoundary.1.i, %while.end17.i ], [ %endIndex, %bNew_block ]

我在llvm-ir代码中做错了什么?我想在llvm-ir代码中插入一些“opaque predicate”。

; Function Attrs: nounwind uwtable
define void @_Z9ArraySortPiii(i32* %array, i32 %startIndex, i32 %endIndex) #3 {
entry:
  %cmp18 = icmp sgt i32 %endIndex, %startIndex
  br i1 %cmp18, label %while.cond1.preheader.i.preheader, label %if.end

while.cond1.preheader.i.preheader:                ; preds = %_Z10SplitArrayPiiii.exit, %entry
  %idxprom16.pn.in = phi i32 [ %inc.i, %_Z10SplitArrayPiiii.exit ], [ %startIndex, %entry ]
  %0 = alloca i32
  store i32 12222, i32* %0
  %1 = load i32* %0
  %predicate_cmp = icmp eq i32 0, %1
  br i1 %predicate_cmp, label %bNew_block, label %while.end.i

bNew_block:                                       ; preds = %while.cond1.preheader.i.preheader
  %idxprom16.pn = sext i32 %idxprom16.pn.in to i64
  %.in = getelementptr inbounds i32* %array, i64 %idxprom16.pn
  %2 = load i32* %.in, align 4
  br label %while.cond1.preheader.i

while.cond1.preheader.i:                          ; preds = %while.end17.i, %bNew_block
  %rightBoundary.046.i = phi i32 [ %rightBoundary.1.i, %while.end17.i ], [ %endIndex, %bNew_block ]
  %leftBoundary.045.i = phi i32 [ %leftBoundary.1.i, %while.end17.i ], [ %idxprom16.pn.in, %bNew_block ]
  %3 = sext i32 %rightBoundary.046.i to i64
  br label %while.cond1.i

while.cond1.i:                                    ; preds = %while.cond1.i, %while.cond1.preheader.i
  %indvars.iv.i = phi i64 [ %indvars.iv.next.i, %while.cond1.i ], [ %3, %while.cond1.preheader.i ]
  %rightBoundary.1.i = phi i32 [ %dec.i, %while.cond1.i ], [ %rightBoundary.046.i, %while.cond1.preheader.i ]
  %arrayidx.i = getelementptr inbounds i32* %array, i64 %indvars.iv.i
  %4 = load i32* %arrayidx.i, align 4, !tbaa !0
  %5 = trunc i64 %indvars.iv.i to i32
  %cmp2.i = icmp sgt i32 %4, %2
  %cmp3.i = icmp sgt i32 %5, %leftBoundary.045.i
  %or.cond.i = and i1 %cmp2.i, %cmp3.i
  %indvars.iv.next.i = add i64 %indvars.iv.i, -1
  %dec.i = add nsw i32 %rightBoundary.1.i, -1
  br i1 %or.cond.i, label %while.cond1.i, label %while.end.i

while.end.i:                                      ; preds = %while.cond1.preheader.i.preheader, %while.cond1.i
  %idxprom5.i = sext i32 %leftBoundary.045.i to i64
  %arrayidx6.i = getelementptr inbounds i32* %array, i64 %idxprom5.i
  %6 = load i32* %arrayidx6.i, align 4, !tbaa !0
  store i32 %4, i32* %arrayidx6.i, align 4, !tbaa !0
  store i32 %6, i32* %arrayidx.i, align 4, !tbaa !0
  br label %while.cond9.i

while.cond9.i:                                    ; preds = %while.cond9.i, %while.end.i
  %indvars.iv48.i = phi i64 [ %indvars.iv.next49.i, %while.cond9.i ], [ %idxprom5.i, %while.end.i ]
  %leftBoundary.1.i = phi i32 [ %inc.i, %while.cond9.i ], [ %leftBoundary.045.i, %while.end.i ]
  %arrayidx11.i = getelementptr inbounds i32* %array, i64 %indvars.iv48.i
  %7 = load i32* %arrayidx11.i, align 4, !tbaa !0
  %8 = trunc i64 %indvars.iv48.i to i32
  %cmp12.i = icmp sle i32 %7, %2
  %cmp14.i = icmp slt i32 %8, %rightBoundary.1.i
  %inc.i = add nsw i32 %leftBoundary.1.i, 1
  %indvars.iv.next49.i = add i64 %indvars.iv48.i, 1
  %or.cond42.i = and i1 %cmp12.i, %cmp14.i
  br i1 %or.cond42.i, label %while.cond9.i, label %while.end17.i

while.end17.i:                                    ; preds = %while.cond9.i
  store i32 %6, i32* %arrayidx11.i, align 4, !tbaa !0
  store i32 %7, i32* %arrayidx.i, align 4, !tbaa !0
  %cmp.i = icmp slt i32 %leftBoundary.1.i, %rightBoundary.1.i
  br i1 %cmp.i, label %while.cond1.preheader.i, label %_Z10SplitArrayPiiii.exit

_Z10SplitArrayPiiii.exit:                         ; preds = %while.end17.i
  %idxprom1 = sext i32 %leftBoundary.1.i to i64
  %arrayidx2 = getelementptr inbounds i32* %array, i64 %idxprom1
  store i32 %2, i32* %arrayidx2, align 4, !tbaa !0
  %sub = add nsw i32 %leftBoundary.1.i, -1
  tail call void @_Z9ArraySortPiii(i32* %array, i32 %idxprom16.pn.in, i32 %sub)
  %cmp = icmp slt i32 %inc.i, %endIndex
  br i1 %cmp, label %while.cond1.preheader.i.preheader, label %if.end

if.end:                                           ; preds = %_Z10SplitArrayPiiii.exit, %entry
  ret void
}

指令不会主导所有用途!

 %rightBoundary.1.i = phi i32 [ %dec.i, %while.cond1.i ], [ %rightBoundary.046.i, %while.cond1.preheader.i ]
  %rightBoundary.046.i = phi i32 [ %rightBoundary.1.i, %while.end17.i ], [ %endIndex, %bNew_block ]
Instruction does not dominate all uses!
  %2 = load i32* %.in, align 4
  %cmp2.i = icmp sgt i32 %4, %2
Instruction does not dominate all uses!
  %leftBoundary.045.i = phi i32 [ %leftBoundary.1.i, %while.end17.i ], [ %idxprom16.pn.in, %bNew_block ]
  %idxprom5.i = sext i32 %leftBoundary.045.i to i64
Instruction does not dominate all uses!
  %4 = load i32* %arrayidx.i, align 4, !tbaa !0
  store i32 %4, i32* %arrayidx6.i, align 4, !tbaa !0
Instruction does not dominate all uses!
  %arrayidx.i = getelementptr inbounds i32* %array, i64 %indvars.iv.i
  store i32 %6, i32* %arrayidx.i, align 4, !tbaa !0
Instruction does not dominate all uses!
  %leftBoundary.045.i = phi i32 [ %leftBoundary.1.i, %while.end17.i ], [ %idxprom16.pn.in, %bNew_block ]
  %leftBoundary.1.i = phi i32 [ %inc.i, %while.cond9.i ], [ %leftBoundary.045.i, %while.end.i ]
Instruction does not dominate all uses!
  %2 = load i32* %.in, align 4
  %cmp12.i = icmp sle i32 %7, %2
Instruction does not dominate all uses!
  %rightBoundary.1.i = phi i32 [ %dec.i, %while.cond1.i ], [ %rightBoundary.046.i, %while.cond1.preheader.i ]
  %cmp14.i = icmp slt i32 %8, %rightBoundary.1.i
Instruction does not dominate all uses!
  %arrayidx.i = getelementptr inbounds i32* %array, i64 %indvars.iv.i
  store i32 %7, i32* %arrayidx.i, align 4, !tbaa !0
Instruction does not dominate all uses!
  %rightBoundary.1.i = phi i32 [ %dec.i, %while.cond1.i ], [ %rightBoundary.046.i, %while.cond1.preheader.i ]
  %cmp.i = icmp slt i32 %leftBoundary.1.i, %rightBoundary.1.i
Instruction does not dominate all uses!
  %2 = load i32* %.in, align 4
  store i32 %2, i32* %arrayidx2, align 4, !tbaa !0

1 个答案:

答案 0 :(得分:0)

指令不支配所有用途意味着您正在使用可能尚未执行的块中的寄存器。

在这种情况下,您可以使用某些块中的phi指令分配的寄存器,而无需执行phi指令即可到达