Files
mercury/compiler
Peter Wang 4365e00a30 Simplify nested case expressions of a specific form generated by the Erlang
Estimated hours taken: 3
Branches: main

Simplify nested case expressions of a specific form generated by the Erlang
backend when calling semidet procedures, where the inner case expression
returns values which is switched on by the outer case expression.  We can move
code from the arms of the outer case expression into the inner case expression.
e.g.

    fib_1_f_0(N_3 ) ->
      (case
	(begin
	  V_4_4 = 2 ,
	  (case
	    N_3 =< V_4_4
	  of
	    true ->
	      {} ;
	    false ->
	      fail
	  end)
	end)
      of
	{} ->
	  HeadVar__2_2 = 1 ,
	  HeadVar__2_2 ;
	_ ->
	  V_8_8 = 1 ,
	  V_7_7 = N_3 - V_8_8 ,
	  V_5_5 = fib_1_f_0(V_7_7 ),
	  V_10_10 = 2 ,
	  V_9_9 = N_3 - V_10_10 ,
	  V_6_6 = fib_1_f_0(V_9_9 ),
	  HeadVar__2_2 = V_5_5 + V_6_6 ,
	  HeadVar__2_2
      end).

===>

    fib_1_f_0(N_3 ) ->
      V_4_4 = 2 ,
      (case
	N_3 =< V_4_4
      of
	true ->
	  HeadVar__2_2 = 1 ,
	  HeadVar__2_2 ;
	false ->
	  V_8_8 = 1 ,
	  V_7_7 = N_3 - V_8_8 ,
	  V_5_5 = fib_1_f_0(V_7_7 ),
	  V_10_10 = 2 ,
	  V_9_9 = N_3 - V_10_10 ,
	  V_6_6 = fib_1_f_0(V_9_9 ),
	  HeadVar__2_2 = V_5_5 + V_6_6 ,
	  HeadVar__2_2
      end).

fib is ~20% faster.


compiler/erl_code_util.m:
	Add a predicate to apply the simplication above.

compiler/erl_call_gen.m:
	Apply the simplication to semidet calls.

compiler/erl_code_gen.m:
	Apply the simplication to disjuncts.

	Unrelated change: don't wrap disjuncts with case expressions when they
	are unnecessary, e.g.

	    case foo() of
		{} -> {};
		fail -> fail
	    end
2007-08-15 01:47:23 +00:00
..
2007-08-01 05:51:04 +00:00
2007-05-23 10:09:24 +00:00
2007-05-23 10:09:24 +00:00
2007-01-23 07:00:38 +00:00
2007-05-30 03:49:50 +00:00
2007-05-23 10:09:24 +00:00
2007-05-23 10:09:24 +00:00
2007-05-23 10:09:24 +00:00
2007-05-23 10:09:24 +00:00