[llvm-bugs] [Bug 27542] New: [llvm.expect] no metadata created if intrinsic is not used by an 'icmp ne'

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Apr 27 09:44:24 PDT 2016


https://llvm.org/bugs/show_bug.cgi?id=27542

            Bug ID: 27542
           Summary: [llvm.expect] no metadata created if intrinsic is not
                    used by an 'icmp ne'
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: spatel+llvm at rotateright.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

int foo(int x) {
  if (__builtin_expect(x, 20) > 10)
    return 234;
  return 0;
}

$ ./clang -O1 expect.c -S -o - -emit-llvm | grep weights
$ 

----------------------------------------------------------------------------

The problem is in the LowerExpectIntrinsic pass. It discards llvm.expect
intrinsics without adding metadata if the expect isn't used by a compare
not-equal:

define i32 @foo(i32 %x) {
entry:
  %conv = sext i32 %x to i64
  %expval = call i64 @llvm.expect.i64(i64 %conv, i64 20)
  %cmp = icmp sgt i64 %expval, 10
  br i1 %cmp, label %if.then, label %if.end

if.then:  
  br label %return

if.end:  
  br label %return

return: 
  %retval.0 = phi i32 [ 234, %if.then ], [ 0, %if.end ]
  ret i32 %retval.0
}

declare i64 @llvm.expect.i64(i64, i64)

----------------------------------------------------------------------------

$ ./opt -lower-expect exp.ll -S
; ModuleID = 'exp.ll'
source_filename = "exp.ll"

define i32 @foo(i32 %x) #0 {
entry:
  %conv = sext i32 %x to i64
  %cmp = icmp sgt i64 %conv, 10
  br i1 %cmp, label %if.then, label %if.end

if.then:                                          ; preds = %entry
  br label %return

if.end:                                           ; preds = %entry
  br label %return

return:                                           ; preds = %if.end, %if.then
  %retval.0 = phi i32 [ 234, %if.then ], [ 0, %if.end ]
  ret i32 %retval.0
}

declare i64 @llvm.expect.i64(i64, i64) #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/20160427/2f234878/attachment.html>


More information about the llvm-bugs mailing list