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: unassignedb...@nondot.org
Reporter: david.bolvan...@gmail.com
CC: llvm-bugs@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs