[LLVMdev] Semantics of an Inbounds GetElementPtr
Daniel Berlin
dberlin at dberlin.org
Mon May 4 12:35:41 PDT 2015
On Mon, May 4, 2015 at 9:40 AM, Nicholas White <n.j.white at gmail.com> wrote:
> Thanks - that makes sense. It's interesting that at -O3 the optimizer
> can't reduce the below though - I'll dig into it a bit and see if I
> can make a patch that fixes it:
I'm unsure what you expect to happen below. It's not quite the same testcase.
GVN will PRE the loads, so you end up with one load.
But i can't see how you expect it to determine anything else.
Can you walk me through the below testcase and epxlain what you expect
to ahppen?
If so, i can probably make it happen for you :)
>
> target datalayout = "e-i64:64-f80:128-n8:16:32:64-S128"
>
> %struct.my_s = type { i32, i32, [0 x i8*] }
>
> ; Function Attrs: noreturn
> declare void @__assert_rtn()
>
> define void @func(i8* %mem) {
> %1 = icmp eq i8* %mem, null
> br i1 %1, label %check.zero, label %stash.zero
>
> stash.zero:
> %2 = bitcast i8* %mem to %struct.my_s*
> %3 = getelementptr inbounds i8, i8* %mem, i64 4
> %4 = bitcast i8* %3 to i32*
> store i32 0, i32* %4, align 4
> br label %check.zero
>
> check.zero:
> %.0.i = phi %struct.my_s* [ %2, %stash.zero ], [ null, %0 ]
> %5 = getelementptr inbounds %struct.my_s, %struct.my_s* %.0.i, i64 0, i32 1
> %6 = load i32, i32* %5, align 4
> %7 = icmp eq i32 %6, 0
> br i1 %7, label %success, label %check.first.array.element
>
> check.first.array.element:
> %8 = getelementptr inbounds %struct.my_s, %struct.my_s* %.0.i, i64
> 0, i32 2, i64 0
> %9 = load i8*, i8** %8, align 1
> %10 = icmp eq i8* %9, null
> br i1 %10, label %success, label %abort
>
> abort:
> tail call void @__assert_rtn()
> unreachable
>
> success:
> ret void
> }
>
> Thanks -
>
> Nick
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
More information about the llvm-dev
mailing list