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>
Hi Sanjay,> 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?>From the bug, it looks like there might be a problem with loopunrolling. Running "opt -loop-unroll -unroll-runtime" on its own performs the dodgy transformation and changes the output. I've not tracked down quite how Clang sets that extra "-unroll-runtime" option (I'd be interested to know myself, actually, having failed). Cheers. Tim.
----- Original Message -----> From: "Tim Northover" <t.p.northover at gmail.com> > To: "Sanjay Patel" <spatel at rotateright.com> > Cc: "LLVM Developers Mailing List" <llvmdev at cs.uiuc.edu> > Sent: Friday, May 23, 2014 2:22:55 PM > Subject: Re: [LLVMdev] clang -O2 versus opt -O2 | llc | clang > > Hi Sanjay, > > > 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? > > From the bug, it looks like there might be a problem with loop > unrolling. Running "opt -loop-unroll -unroll-runtime" on its own > performs the dodgy transformation and changes the output. > > I've not tracked down quite how Clang sets that extra > "-unroll-runtime" option (I'd be interested to know myself, actually, > having failed).It doesn't, but the backend can by overriding TTI::getUnrollingPreferences or setting LoopMicroOpBufferSize in the processor scheduling model. -Hal> > Cheers. > > Tim. > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >-- Hal Finkel Assistant Computational Scientist Leadership Computing Facility Argonne National Laboratory