[LLVMdev] Semantics of an Inbounds GetElementPtr
Nicholas White
n.j.white at gmail.com
Mon May 4 09:40:38 PDT 2015
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:
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
More information about the llvm-dev
mailing list