0

I have llvm-IR function When i try it convert to .bc, llvm-as has showed a lot of error. For example:

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 ]

What i do wrong in llvm-ir code? I would like insert few "opaque predicate" in llvm-ir code.

; 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
}

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 ]
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
chiwangc
  • 3,566
  • 16
  • 26
  • 32
llvmuser12
  • 33
  • 2

1 Answers1

0

Instruction does not dominate all uses means you're using a register from a block that may not have been executed.

It looks like in this case you're using the register assigned to by the phi instruction in some block that could be reached without executing the phi instruction

Colin LeMahieu
  • 610
  • 5
  • 7
  • Can you show me some example? i don't understand fully: " It looks like in this case you're using the register assigned to by the phi instruction in some block that could be reached without executing the phi instruction " – llvmuser12 Apr 22 '15 at 15:59
  • define void @foo(i1 %a) { entry: br i1 %a, label %one, label %exit one: %b = xor i1 %a, %a br label %exit exit: %c = xor i1 %b, %b ret void } %c will generate a dominator error since it uses %b but %b might not have ever been created – Colin LeMahieu Apr 22 '15 at 18:34