[m-rev.] for review: Simplify away self-comparisons of int types in pregen grades.

Peter Wang novalazy at gmail.com
Tue Oct 23 17:03:23 AEDT 2018


Previously we would simplify away self-comparisons of `int' and `uint'
variables in .pregen grades; rectify that now.

compiler/simplify_goal_call.m:
    As above.

diff --git a/compiler/simplify_goal_call.m b/compiler/simplify_goal_call.m
index 45a518450..ffc57cfbe 100644
--- a/compiler/simplify_goal_call.m
+++ b/compiler/simplify_goal_call.m
@@ -1027,21 +1027,23 @@ simplify_build_compare_ite(CmpLtGoal, CmpGtGoal, R, X, Y, Context,
 
 :- pred simplify_improve_int_call(instmap::in, string::in, string::in,
     int::in, list(prog_var)::in, hlds_goal_expr::out,
     hlds_goal_info::in, hlds_goal_info::out,
     simplify_info::in, simplify_info::out) is semidet.
 
 simplify_improve_int_call(InstMap0, ModuleName, PredName, ModeNum, Args,
         ImprovedGoalExpr, !GoalInfo, !Info) :-
     simplify_info_get_module_info(!.Info, ModuleInfo),
     module_info_get_globals(ModuleInfo, Globals),
-    globals.lookup_bool_option(Globals, pregenerated_dist, no),
+    globals.lookup_bool_option(Globals, pregenerated_dist, PregeneratedDist),
+    (
+        PregeneratedDist = no,
         target_bits_per_int(Globals, bits_per_int(TargetBitsPerInt)),
         ( if PredName = "quot_bits_per_int" then
             Args = [X, Y],
             % There is no point in checking whether bits_per_int is 0;
             % it isn't.
             Op = "unchecked_quotient",
             simplify_make_int_ico_op(ModuleName, Op, X, TargetBitsPerInt, Y,
                 ImprovedGoalExpr, !.GoalInfo, !Info)
         else if PredName = "times_bits_per_int" then
             Args = [X, Y],
@@ -1051,20 +1053,25 @@ simplify_improve_int_call(InstMap0, ModuleName, PredName, ModeNum, Args,
         else if PredName = "rem_bits_per_int" then
             Args = [X, Y],
             % There is no point in checking whether bits_per_int is 0;
             % it isn't.
             Op = "unchecked_rem",
             simplify_make_int_ico_op(ModuleName, Op, X, TargetBitsPerInt, Y,
                 ImprovedGoalExpr, !.GoalInfo, !Info)
         else
             simplify_improve_int_type_call(int_type_int, InstMap0, ModuleName,
                 PredName, ModeNum, Args, ImprovedGoalExpr, !GoalInfo, !Info)
+        )
+    ;
+        PregeneratedDist = yes,
+        simplify_improve_int_type_comparison_call(ModuleName, PredName,
+            ModeNum, Args, ImprovedGoalExpr)
     ).
 
     % simplify_make_int_ico_op(ModuleName, Op, X, IntConst, Y, GoalExpr,
     %   OrigGoalInfo, !Info):
     %
     % Return a GoalExpr that computes Y := X Op IntConst.
     % (The ico stands for the three arguments being Input, Constant input,
     % and Output.)
     %
 :- pred simplify_make_int_ico_op(string::in, string::in,
@@ -1161,31 +1168,38 @@ simplify_make_int_const(IntConst, ConstVar, Goal, !Info) :-
 
 :- pred simplify_improve_uint_call(instmap::in, string::in, string::in,
     int::in, list(prog_var)::in, hlds_goal_expr::out,
     hlds_goal_info::in, hlds_goal_info::out,
     simplify_info::in, simplify_info::out) is semidet.
 
 simplify_improve_uint_call(InstMap0, ModuleName, PredName, ModeNum, Args,
         ImprovedGoalExpr, !GoalInfo, !Info) :-
     simplify_info_get_module_info(!.Info, ModuleInfo),
     module_info_get_globals(ModuleInfo, Globals),
-    globals.lookup_bool_option(Globals, pregenerated_dist, no),
+    globals.lookup_bool_option(Globals, pregenerated_dist, PregeneratedDist),
+    (
+        PregeneratedDist = no,
         simplify_improve_int_type_call(int_type_uint, InstMap0, ModuleName,
-        PredName, ModeNum, Args, ImprovedGoalExpr, !GoalInfo, !Info).
+            PredName, ModeNum, Args, ImprovedGoalExpr, !GoalInfo, !Info)
+    ;
+        PregeneratedDist = yes,
+        simplify_improve_int_type_comparison_call(ModuleName, PredName,
+            ModeNum, Args, ImprovedGoalExpr)
+    ).
 
 :- pred simplify_improve_int_type_call(int_type::in, instmap::in, string::in,
     string::in, int::in, list(prog_var)::in, hlds_goal_expr::out,
     hlds_goal_info::in, hlds_goal_info::out,
     simplify_info::in, simplify_info::out) is semidet.
 
 simplify_improve_int_type_call(IntType, InstMap0, ModuleName, PredName,
-        _ModeNum, Args, ImprovedGoalExpr, !GoalInfo, !Info) :-
+        ModeNum, Args, ImprovedGoalExpr, !GoalInfo, !Info) :-
     simplify_info_get_module_info(!.Info, ModuleInfo),
     module_info_get_globals(ModuleInfo, Globals),
     (
         ( PredName = "/"
         ; PredName = "//"
         ),
         Args = [X, Y, Z],
         instmap_lookup_var(InstMap0, Y, InstY),
         InstY = bound(_, _, [bound_functor(ConsY, [])]),
         is_non_zero_const(IntType, ConsY),
@@ -1215,20 +1229,35 @@ simplify_improve_int_type_call(IntType, InstMap0, ModuleName, PredName,
         PredName = ">>",
         Args = [X, Y, Z],
         instmap_lookup_var(InstMap0, Y, InstY),
         InstY = bound(_, _, [bound_functor(int_const(YVal), [])]),
         YVal >= 0,
         YVal < int_type_target_bits(Globals, IntType),
         Op = "unchecked_right_shift",
         simplify_make_binary_op_goal_expr(!.Info, ModuleName, Op,
             inline_builtin, X, Y, Z, ImprovedGoalExpr)
     ;
+        ( PredName = "<"
+        ; PredName = ">"
+        ; PredName = "=<"
+        ; PredName = ">="
+        ),
+        simplify_improve_int_type_comparison_call(ModuleName, PredName,
+            ModeNum, Args, ImprovedGoalExpr)
+    ).
+
+:- pred simplify_improve_int_type_comparison_call(string::in, string::in,
+    int::in, list(prog_var)::in, hlds_goal_expr::out) is semidet.
+
+simplify_improve_int_type_comparison_call(_ModuleName, PredName, _ModeNum,
+        Args, ImprovedGoalExpr) :-
+    (
         ( PredName = "<"
         ; PredName = ">"
         ),
         Args = [X, X],
         ImprovedGoalExpr = fail_goal_expr
     ;
         ( PredName = "=<"
         ; PredName = ">="
         ),
         Args = [X, X],
-- 
2.19.1



More information about the reviews mailing list