[LLVMdev] clang -O2 versus opt -O2 | llc | clang

Sanjay Patel spatel at rotateright.com
Fri May 23 11:29:19 PDT 2014


I'm investigating a miscompilation bug (
http://llvm.org/bugs/show_bug.cgi?id=19823 ), but I've run into a problem:
the output of the program is different when I compile the IR with clang
compared to opt | llc | clang. Any clues on how to resolve this difference?

$ ./opt -O1 19823.ll | ./llc | ./clang -x assembler - -o a.out ; ./a.out ;
echo $?
1
$ ./opt -O2 19823.ll | ./llc | ./clang -x assembler - -o a.out ; ./a.out ;
echo $?
1
$ ./clang -O1 19823.ll ; ./a.out ; echo $?
1
$ ./clang -O2 19823.ll ; ./a.out ; echo $?
0   <--- that's bad!


The IR is pretty simple:
@a = common global i16 0, align 2
@c = global i16* @a, align 8
@d = global i8 0, align 1
@b = common global i16 0, align 2

; Function Attrs: nounwind ssp uwtable
define i32 @main() #0 {
entry:
  %0 = load i16** @c, align 8, !tbaa !1
  %d.promoted = load i8* @d, align 1, !tbaa !5
  br label %lbl

lbl:                                              ; preds = %lbl, %entry
  %1 = phi i8 [ %dec, %lbl ], [ %d.promoted, %entry ]
  %dec = add i8 %1, -1
  %conv = sext i8 %1 to i16
  store i16 %conv, i16* @b, align 2, !tbaa !6
  store i16 1, i16* %0, align 2, !tbaa !6
  %tobool = icmp eq i8 %dec, 0
  br i1 %tobool, label %if.end, label %lbl

if.end:                                           ; preds = %lbl
  store i8 0, i8* @d, align 1, !tbaa !5
  %2 = load i16* @a, align 2, !tbaa !6
  %conv1 = sext i16 %2 to i32
  ret i32 %conv1
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140523/6a5fb5ca/attachment.html>


More information about the llvm-dev mailing list