<html>
<head>
<base href="http://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - Clang optimized out a branch function with Os option"
href="http://llvm.org/bugs/show_bug.cgi?id=16744">16744</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Clang optimized out a branch function with Os option
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>3.3
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>-New Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>mrcool0905@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=10954" name="attach_10954" title="an example code">attachment 10954</a> <a href="attachment.cgi?id=10954&action=edit" title="an example code">[details]</a></span>
an example code
I Have some code like this. With Os option, I don't see any branching to
xQueueGenericSend in assembly. Clang 3.2 works correctly in this case.
(pxMutex->uxRecursiveCallCount)--;
if( pxMutex->uxRecursiveCallCount == 0 )
{
xQueueGenericSend( pxMutex, 0, queueMUTEX_GIVE_BLOCK_TIME);
xReturn = pdPASS;
}
/usr/local/rui/toolchains/llvm/3.3/armv7m/bin/clang -mcpu=cortex-m4 -nostdinc
-isystem /usr/local/rui/toolchains/llvm/3.3/armv7m/lib/clang/3.3/include
-mthumb -O2 -Os -c -o test.o test.c
The llvm bytecode generated with -S -emit-llvm:
; ModuleID = 'test.c'
target datalayout =
"e-p:32:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:64:128-a0:0:32-n32-S64"
target triple = "thumbv7em-none--eabi"
%struct.QueueDefinition = type { i8*, i8*, i8*, i8*, i32, i32, i32, i32, i32,
i8 }
; Function Attrs: nounwind optsize
define i32 @xQueueGiveMutexRecursive(%struct.QueueDefinition* nocapture
%pxMutex) #0 {
entry:
%pcTail = getelementptr inbounds %struct.QueueDefinition* %pxMutex, i32 0,
i32 1
%0 = load i8** %pcTail, align 4, !tbaa !0
%call = tail call i8* @xTaskGetCurrentTaskHandle() #2
%cmp = icmp eq i8* %0, %call
br i1 %cmp, label %if.then, label %if.end5
if.then: ; preds = %entry
%pcReadFrom = getelementptr inbounds %struct.QueueDefinition* %pxMutex, i32
0, i32 3
%1 = load i8** %pcReadFrom, align 4, !tbaa !0
%incdec.ptr = getelementptr inbounds i8* %1, i32 -1
store i8* %incdec.ptr, i8** %pcReadFrom, align 4, !tbaa !0
br label %if.end5
if.end5: ; preds = %entry, %if.then
ret i32 0
}
; Function Attrs: optsize
declare i8* @xTaskGetCurrentTaskHandle() #1
attributes #0 = { nounwind optsize "less-precise-fpmad"="false"
"no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf"="true"
"no-infs-fp-math"="false" "no-nans-fp-math"="false" "unsafe-fp-math"="false"
"use-soft-float"="false" }
attributes #1 = { optsize "less-precise-fpmad"="false"
"no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf"="true"
"no-infs-fp-math"="false" "no-nans-fp-math"="false" "unsafe-fp-math"="false"
"use-soft-float"="false" }
attributes #2 = { nounwind optsize }
!0 = metadata !{metadata !"any pointer", metadata !1}
!1 = metadata !{metadata !"omnipotent char", metadata !2}
!2 = metadata !{metadata !"Simple C/C++ TBAA"}
Disassembly of section .text:
00000000 <xQueueGiveMutexRecursive>:
0: b5b0 push {r4, r5, r7, lr}
2: 4604 mov r4, r0
4: af02 add r7, sp, #8
6: 6865 ldr r5, [r4, #4]
8: f7ff fffe bl 0 <xTaskGetCurrentTaskHandle>
c: 4285 cmp r5, r0
e: bf02 ittt eq
10: 68e0 ldreq r0, [r4, #12]
12: 3801 subeq r0, #1
14: 60e0 streq r0, [r4, #12]
16: 2000 movs r0, #0
18: bdb0 pop {r4, r5, r7, pc}
1a: bf00 nop</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>