[llvm-bugs] [Bug 27541] New: [llvm.expect] no metadata created if intrinsic is not used directly by a cmp
    via llvm-bugs 
    llvm-bugs at lists.llvm.org
       
    Wed Apr 27 09:35:24 PDT 2016
    
    
  
https://llvm.org/bugs/show_bug.cgi?id=27541
            Bug ID: 27541
           Summary: [llvm.expect] no metadata created if intrinsic is not
                    used directly by a cmp
           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 n) {
  int b = __builtin_expect(n, 1);
  if (b) { return 24; }
  return 234;
}
$ ./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 directly by a
branch or compare:
define i32 @foo(i32 %n) {
entry:
  %conv = sext i32 %n to i64
  %expval = call i64 @llvm.expect.i64(i64 %conv, i64 1)
  %conv1 = trunc i64 %expval to i32
  %tobool = icmp ne i32 %conv1, 0
  br i1 %tobool, label %if.then, label %if.end
if.then:
  br label %cleanup
if.end:
  br label %cleanup
cleanup:
  %retval.0 = phi i32 [ 24, %if.then ], [ 234, %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 %n) {
entry:
  %conv = sext i32 %n to i64
  %conv1 = trunc i64 %conv to i32
  %tobool = icmp ne i32 %conv1, 0
  br i1 %tobool, label %if.then, label %if.end
if.then:                                          ; preds = %entry
  br label %cleanup
if.end:                                           ; preds = %entry
  br label %cleanup
cleanup:                                          ; preds = %if.end, %if.then
  %retval.0 = phi i32 [ 24, %if.then ], [ 234, %if.end ]
  ret i32 %retval.0
}
; Function Attrs: nounwind readnone
declare i64 @llvm.expect.i64(i64, i64) #0
attributes #0 = { nounwind readnone }
-- 
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/fd5c24bd/attachment.html>
    
    
More information about the llvm-bugs
mailing list