Stripf, Timo
2009-Aug-11 08:13 UTC
[LLVMdev] Bug in optimization pass related to strcmp and big endian back-ends
Hi all,
i'm working on a LLVM back-end right now and i think I found a bug in an
optimization pass. When compiling the following code using llvm-gcc (the
current 2.5 release) with -O2
int main(int argc, char** argv) {
char* pStr = "I" + (argc > 100);
printf("%d\n", strcmp(pStr, "I") == 0);
}
the strcmp function is replaced by a 16 bit load and compared against
the integer value of 'I':
define i32 @main(i32 %argc, i8** nocapture %argv) nounwind {
entry:
%0 = icmp sgt i32 %argc, 100 ; <i1> [#uses=1]
%1 = zext i1 %0 to i32 ; <i32> [#uses=1]
%2 = getelementptr [2 x i8]* @.str, i32 0, i32 %1
; <i8*> [#uses=1]
%tmp = bitcast i8* %2 to i16* ; <i16*>
[#uses=1]
%lhsv = load i16* %tmp, align 1 ; <i16>
[#uses=1]
%3 = icmp eq i16 %lhsv, 73 ; <i1> [#uses=1]
%4 = zext i1 %3 to i32 ; <i32> [#uses=1]
%5 = tail call i32 (i8*, ...)* @printf(i8* getelementptr ([4
x i8]* @.str1, i32 0, i32 0), i32 %4) nounwind ;
<i32> [#uses=0]
ret i32 undef
}
On little endian machines the code works correct but on big endian %lhsv
must be compared against 73 << 8.
Kind regards
Timo Stripf
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20090811/9ec73875/attachment.html>
Eli Friedman
2009-Aug-11 08:27 UTC
[LLVMdev] Bug in optimization pass related to strcmp and big endian back-ends
On Tue, Aug 11, 2009 at 1:13 AM, Stripf, Timo<Timo.Stripf at itiv.uni-karlsruhe.de> wrote:> On little endian machines the code works correct but on big endian %lhsv > must be compared against 73 << 8.If llvm-gcc thinks it's compiling for a little-endian target, the optimizers will assume the target is little-endian... what are you trying to do? -Eli
Stripf, Timo
2009-Aug-11 09:24 UTC
[LLVMdev] Bug in optimization pass related to strcmp and bigendian back-ends
I thought the LLVM IR is target independent and that "llvm-gcc -c -emit-llvm -O2" produces target independent code. I'm working on a back-end and use llvm-gcc to first generate the bc file. Afterwards I use llc including the new back-end to produce the assembler file. -Timo -----Ursprüngliche Nachricht----- Von: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] Im Auftrag von Eli Friedman Gesendet: Dienstag, 11. August 2009 10:27 An: LLVM Developers Mailing List Betreff: Re: [LLVMdev] Bug in optimization pass related to strcmp and bigendian back-ends On Tue, Aug 11, 2009 at 1:13 AM, Stripf, Timo<Timo.Stripf at itiv.uni-karlsruhe.de> wrote:> On little endian machines the code works correct but on big endian %lhsv > must be compared against 73 << 8.If llvm-gcc thinks it's compiling for a little-endian target, the optimizers will assume the target is little-endian... what are you trying to do? -Eli _______________________________________________ LLVM Developers mailing list LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Apparently Analagous Threads
- [LLVMdev] Bug in optimization pass related to strcmp and bigendian back-ends
- [LLVMdev] Bug in optimization pass related to strcmp and bigendian back-ends
- [LLVMdev] Bug in optimization pass related to strcmp and big endian back-ends
- [LLVMdev] Bug in optimization pass related to strcmp and bigendian back-ends
- [LLVMdev] Bug in optimization pass related to strcmp and big endian back-ends