[LLVMbugs] [Bug 4284] New: memcmp() optimizer is not 8-bit clean

bugzilla-daemon at cs.uiuc.edu bugzilla-daemon at cs.uiuc.edu
Sat May 30 10:09:37 PDT 2009


http://llvm.org/bugs/show_bug.cgi?id=4284

           Summary: memcmp() optimizer is not 8-bit clean
           Product: libraries
           Version: trunk
          Platform: PC
        OS/Version: FreeBSD
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Transformation Utilities
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: ed at 80386.nl
                CC: llvmbugs at cs.uiuc.edu
            Blocks: 3696


The following code works when built with Clang without optimization, but fails
when optimization is enabled. The code is obtained from OpenLDAP's configure
script.

#include <stdio.h>
#include <string.h>

int
main(int argc, char *argv[])
{
        char c0 = '\100', c1 = '\200', c2 = '\201';

        if (memcmp(&c0, &c2, 1) >= 0 || memcmp(&c1, &c2, 1) >= 0) {
                puts("Test failed");
                return (1);
        }

        puts("Test passed");
        return (0);
}

; ModuleID = 'memcmp.c'
target datalayout =
"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
target triple = "x86_64-undermydesk-freebsd8.0"
@.str = internal constant [12 x i8] c"Test failed\00"           ; <[12 x i8]*>
[#uses=1]
@.str1 = internal constant [12 x i8] c"Test passed\00"          ; <[12 x i8]*>
[#uses=1]

define i32 @main(i32 %argc, i8** %argv) nounwind {
entry:
        %retval = alloca i32            ; <i32*> [#uses=3]
        %argc.addr = alloca i32         ; <i32*> [#uses=1]
        %argv.addr = alloca i8**                ; <i8***> [#uses=1]
        %c0 = alloca i8, align 1                ; <i8*> [#uses=2]
        %c1 = alloca i8, align 1                ; <i8*> [#uses=2]
        %c2 = alloca i8, align 1                ; <i8*> [#uses=3]
        store i32 %argc, i32* %argc.addr
        store i8** %argv, i8*** %argv.addr
        store i8 64, i8* %c0
        store i8 -128, i8* %c1
        store i8 -127, i8* %c2
        %call = call i32 @memcmp(i8* %c0, i8* %c2, i64 1) readonly             
; <i32> [#uses=1]
        %cmp = icmp sge i32 %call, 0            ; <i1> [#uses=1]
        br i1 %cmp, label %if.then, label %lor.lhs.false

lor.lhs.false:          ; preds = %entry
        %call1 = call i32 @memcmp(i8* %c1, i8* %c2, i64 1) readonly            
; <i32> [#uses=1]
        %cmp2 = icmp sge i32 %call1, 0          ; <i1> [#uses=1]
        br i1 %cmp2, label %if.then, label %if.end

if.then:                ; preds = %lor.lhs.false, %entry
        %call3 = call i32 @puts(i8* getelementptr ([12 x i8]* @.str, i32 0, i32
0))             ; <i32> [#uses=0]
        store i32 1, i32* %retval
        br label %return

if.end:         ; preds = %lor.lhs.false
        %call4 = call i32 @puts(i8* getelementptr ([12 x i8]* @.str1, i32 0,
i32 0))            ; <i32> [#uses=0]
        store i32 0, i32* %retval
        br label %return

return:         ; preds = %if.end, %if.then
        %0 = load i32* %retval          ; <i32> [#uses=1]
        ret i32 %0
}

declare i32 @memcmp(i8*, i8*, i64) readonly

declare i32 @puts(i8*)


-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list