Skip to content
  • Chris Lattner's avatar
    Make emission of 'if' conditions much more sophisticated when we · b7a9e164
    Chris Lattner authored
    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.
    
    llvm-svn: 59111
    b7a9e164
Loading