<div dir="ltr"><div><div><br clear="all"></div>I'm investigating a miscompilation bug ( <a href="http://llvm.org/bugs/show_bug.cgi?id=19823">http://llvm.org/bugs/show_bug.cgi?id=19823</a> ), 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?<br>
<br>$ ./opt -O1 19823.ll | ./llc | ./clang -x assembler - -o a.out ; ./a.out ; echo $?<br>1<br>$ ./opt -O2 19823.ll | ./llc | ./clang -x assembler - -o a.out ; ./a.out ; echo $?<br>1<br>$ ./clang -O1 19823.ll ; ./a.out ; echo $?<br>
1<br>$ ./clang -O2 19823.ll ; ./a.out ; echo $?<br></div><div>0 <--- that's bad!<br></div><div><br><br></div>The IR is pretty simple:<br>@a = common global i16 0, align 2<br>@c = global i16* @a, align 8<br>@d = global i8 0, align 1<br>
@b = common global i16 0, align 2<br><br>; Function Attrs: nounwind ssp uwtable<br>define i32 @main() #0 {<br>entry:<br> %0 = load i16** @c, align 8, !tbaa !1<br> %d.promoted = load i8* @d, align 1, !tbaa !5<br> br label %lbl<br>
<br>lbl: ; preds = %lbl, %entry<br> %1 = phi i8 [ %dec, %lbl ], [ %d.promoted, %entry ]<br> %dec = add i8 %1, -1<br> %conv = sext i8 %1 to i16<br> store i16 %conv, i16* @b, align 2, !tbaa !6<br>
store i16 1, i16* %0, align 2, !tbaa !6<br> %tobool = icmp eq i8 %dec, 0<br> br i1 %tobool, label %if.end, label %lbl<br><br>if.end: ; preds = %lbl<br> store i8 0, i8* @d, align 1, !tbaa !5<br>
%2 = load i16* @a, align 2, !tbaa !6<br> %conv1 = sext i16 %2 to i32<br> ret i32 %conv1<br>}<br><div><div><div><br></div></div></div></div>