[llvm-dev] Rép : Clearing the BSS section
devh8h via llvm-dev
llvm-dev at lists.llvm.org
Sat Aug 29 02:28:48 PDT 2015
> It'd be better to make the both zero-sized, like an array of i8 with zero elements. This idiom has come up before, and that's our recommended solution. We've tweaked the optimizers to ensure that zero-sized objects are not assumed to be distinct.
Okay, I have rewritten my clear BSS section function as :
;————
@__bss_start = external global [0 x i32]
@__bss_end = external global [0 x i32]
define void @clearBSS () nounwind {
entry:
%startPtr = getelementptr [0 x i32], [0 x i32]* @__bss_start, i32 0, i32 0
%endPtr = getelementptr [0 x i32], [0 x i32]* @__bss_end, i32 0, i32 0
br label %bssLoopTest
bssLoopTest:
%p = phi i32* [%startPtr, %entry], [%p.next, %bssLoop]
%completed = icmp eq i32* %p, %endPtr
br i1 %completed, label %clearCompleted, label %bssLoop
bssLoop:
store i32 0, i32* %p, align 4
%p.next = getelementptr inbounds i32, i32* %p, i32 1
br label %bssLoopTest
clearCompleted:
ret void
}
;————
It works, opt preserves the while loop.
Thanks,
Pierre Molinaro
> Le 28 août 2015 à 17:59, Reid Kleckner via llvm-dev <llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org>> a écrit :
>
> On Fri, Aug 28, 2015 at 8:27 AM, Joerg Sonnenberger via llvm-dev <llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org>> wrote:
> On Fri, Aug 28, 2015 at 04:52:56PM +0200, devh8h via llvm-dev wrote:
> > Is there a way to prevent the optimizer to assume the two variables
> > are distinct ? Or what is the proper way to deal with link time values ?
>
> Make one of them weak.
>
> It'd be better to make the both zero-sized, like an array of i8 with zero elements. This idiom has come up before, and that's our recommended solution. We've tweaked the optimizers to ensure that zero-sized objects are not assumed to be distinct.
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org>
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev <http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150829/e6841300/attachment.html>
More information about the llvm-dev
mailing list