]> granicus.if.org Git - clang/commit
Make emission of 'if' conditions much more sophisticated when we
authorChris Lattner <sabre@nondot.org>
Wed, 12 Nov 2008 07:46:33 +0000 (07:46 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 12 Nov 2008 07:46:33 +0000 (07:46 +0000)
commit9bc47e29dce8f095be7a6d07dbb02a5a7a112949
treed2cb6a21700ee6cb983a889e5b6704676f5f2f40
parent32fea9d18cc3658a1b01df5ca6f2ac302625c61d
Make emission of 'if' conditions much more sophisticated when we
have a condition that is an &&/||.  Before we used to compile things like this:

int test() {
  if (x && y) foo(); else bar();
}

into:

%0 = load i32* @x ; <i32> [#uses=1]
%1 = icmp ne i32 %0, 0 ; <i1> [#uses=1]
br i1 %1, label %land_rhs, label %land_cont

land_rhs: ; preds = %entry
%2 = load i32* @y ; <i32> [#uses=1]
%3 = icmp ne i32 %2, 0 ; <i1> [#uses=1]
br label %land_cont

land_cont: ; preds = %land_rhs, %entry
%4 = phi i1 [ false, %entry ], [ %3, %land_rhs ] ; <i1> [#uses=1]
br i1 %4, label %ifthen, label %ifelse

ifthen: ; preds = %land_cont
%call = call i32 (...)* @foo() ; <i32> [#uses=0]
br label %ifend

ifelse: ; preds = %land_cont
%call1 = call i32 (...)* @bar() ; <i32> [#uses=0]
br label %ifend

ifend: ; preds = %ifelse, %ifthen

Now we turn it into the much more svelte code:

        %0 = load i32* @x               ; <i32> [#uses=1]
        %1 = icmp ne i32 %0, 0          ; <i1> [#uses=1]
        br i1 %1, label %land_lhs_true, label %ifelse

land_lhs_true:          ; preds = %entry
        %2 = load i32* @y               ; <i32> [#uses=1]
        %3 = icmp ne i32 %2, 0          ; <i1> [#uses=1]
        br i1 %3, label %ifthen, label %ifelse

ifthen:         ; preds = %land_lhs_true
        %call = call i32 (...)* @foo()          ; <i32> [#uses=0]
        br label %ifend

ifelse:         ; preds = %land_lhs_true, %entry
        %call1 = call i32 (...)* @bar()         ; <i32> [#uses=0]
        br label %ifend

ifend:          ; preds = %ifelse, %ifthen

Note the lack of a phi node.

This shrinks the -O0 .ll file for 176.gcc/expr.c from 43176 to 40267 lines.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59111 91177308-0d34-0410-b5e6-96231b3b80d8
lib/CodeGen/CGStmt.cpp
lib/CodeGen/CodeGenFunction.h