[llvm-bugs] [Bug 41688] New: Optimizer ignores __builtin_unreachable

via llvm-bugs llvm-bugs at lists.llvm.org
Wed May 1 09:48:39 PDT 2019


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

            Bug ID: 41688
           Summary: Optimizer ignores __builtin_unreachable
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: david.bolvansky at gmail.com
                CC: llvm-bugs at lists.llvm.org

int foo(int p)
{
   if (p <= 0) __builtin_unreachable();
   return abs(p);
}

Clang sadly ignores this hint and produces:

foo(int):                           
        mov     eax, edi
        neg     eax
        cmovl   eax, edi
        ret

** IR Dump After Instrument function entry/exit with calls to e.g. mcount()
(pre inlining) ***
; Function Attrs: nounwind uwtable
define dso_local i32 @foo(i32 %p) #0 {
entry:
  %p.addr = alloca i32, align 4
  store i32 %p, i32* %p.addr, align 4, !tbaa !2
  %0 = load i32, i32* %p.addr, align 4, !tbaa !2
  %cmp = icmp sle i32 %0, 0
  br i1 %cmp, label %if.then, label %if.end

if.then:                                          ; preds = %entry
  unreachable

if.end:                                           ; preds = %entry
  %1 = load i32, i32* %p.addr, align 4, !tbaa !2
  %call = call i32 @abs(i32 %1) #2
  ret i32 %call
}
*** IR Dump After Simplify the CFG ***
; Function Attrs: nounwind uwtable
define dso_local i32 @foo(i32 %p) #0 {
entry:
  %p.addr = alloca i32, align 4
  store i32 %p, i32* %p.addr, align 4, !tbaa !2
  %0 = load i32, i32* %p.addr, align 4, !tbaa !2
  %call = call i32 @abs(i32 %0) #2
  ret i32 %call
}
*** IR Dump After SROA ***
; Function Attrs: nounwind uwtable
define dso_local i32 @foo(i32 %p) #0 {
entry:
  %call = call i32 @abs(i32 %p) #2
  ret i32 %call
}



When Simplify CFG removes unreachable branch, maybe it should also add
llvm.assume on branch condition, no?

-- 
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/20190501/ad802eea/attachment-0001.html>


More information about the llvm-bugs mailing list