Skip to content

Failure to notice that all arguments of a phi are the same #13679

@llvmbot

Description

@llvmbot
Bugzilla Link 13307
Version trunk
OS Linux
Reporter LLVM Bugzilla Contributor
CC @jrmuizel

Extended Description

We compile

void * malloc_rtree_get(void **node) {
void *ret;
unsigned i;

for (i = 0; i < 10; i++) {
void child = (void)node[0];
if (child == ((void*)0)) {
return (((void*)0));
}
node = child;
}
ret = node[0];
return (ret);
}

to

define i8* @​malloc_rtree_get(i8** nocapture %node) nounwind uwtable readonly ssp {
entry:
br label %for.cond
for.cond: ; preds = %if.end, %entry
%i.0 = phi i32 [ 0, %entry ], [ %inc, %if.end ]
%node.addr.0 = phi i8** [ %node, %entry ], [ %1, %if.end ]
%cmp = icmp ult i32 %i.0, 10
%0 = load i8** %node.addr.0, align 8, !tbaa !​0
br i1 %cmp, label %for.body, label %return
for.body: ; preds = %for.cond
%cmp1 = icmp eq i8* %0, null
br i1 %cmp1, label %return, label %if.end
if.end: ; preds = %for.body
%1 = bitcast i8* %0 to i8**
%inc = add i32 %i.0, 1
br label %for.cond
return: ; preds = %for.cond, %for.body
%retval.0 = phi i8* [ null, %for.body ], [ %0, %for.cond ]
ret i8* %retval.0
}

Note that if we jump from for.body to return then %0 is null and we could just use %0 instead of creating %retval.0.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions