[LLVMbugs] [Bug 16425] New: llvm.expect() lowering loses information

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sun Jun 23 09:48:44 PDT 2013


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

            Bug ID: 16425
           Summary: llvm.expect() lowering loses information
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: nunoplopes at sapo.pt
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

The lowering of llvm.expect() functionality doesn't understand the idiom that
clang emits for __builtin_expect(a || b, 0) and ends up losing information.


int a(void);
int b(void);

int f() {
  if (__builtin_expect(a() || b(), 0))
    return 0;
  return 42;
}


ends up with no branch information:

define i32 @f() #0 {
entry:
  %call = tail call i32 @a() #2
  %tobool = icmp eq i32 %call, 0
  br i1 %tobool, label %lor.rhs, label %lor.end

lor.rhs:                                          ; preds = %entry
  %call1 = tail call i32 @b() #2
  %tobool2 = icmp ne i32 %call1, 0
  %phitmp = select i1 %tobool2, i32 0, i32 42
  br label %lor.end

lor.end:                                          ; preds = %entry, %lor.rhs
  %0 = phi i32 [ 0, %entry ], [ %phitmp, %lor.rhs ]
  ret i32 %0
}


clang emits the following bitcode:

define i32 @f() #0 {
entry:
  %retval = alloca i32, align 4
  %call = call i32 @a()
  %tobool = icmp ne i32 %call, 0
  br i1 %tobool, label %lor.end, label %lor.rhs

lor.rhs:                                          ; preds = %entry
  %call1 = call i32 @b()
  %tobool2 = icmp ne i32 %call1, 0
  br label %lor.end

lor.end:                                          ; preds = %lor.rhs, %entry
  %0 = phi i1 [ true, %entry ], [ %tobool2, %lor.rhs ]
  %lor.ext = zext i1 %0 to i32
  %expval = call i32 @llvm.expect.i32(i32 %lor.ext, i32 0)
  %tobool3 = icmp ne i32 %expval, 0
  br i1 %tobool3, label %if.then, label %if.end

if.then:                                          ; preds = %lor.end
  store i32 0, i32* %retval
  br label %return

if.end:                                           ; preds = %lor.end
  store i32 42, i32* %retval
  br label %return

return:                                           ; preds = %if.end, %if.then
  %1 = load i32* %retval
  ret i32 %1
}

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20130623/61197a77/attachment.html>


More information about the llvm-bugs mailing list