Mercury Bugs - mercury
View Issue Details
0000085mercuryBugpublic2008-09-23 09:442008-09-23 18:45
Reporterjuliensf 
Assigned To 
PrioritynormalSeverityminorReproducibilityalways
StatusnewResolutionopen 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0000085: stage 1 compiler aborts when compiled with -O5 --intermodule-optimization
Description
Compilation of compiler/deep_profiling.m fails in grade asm_fast.gc with
-O5 --intermodule-optimization using ROTD 2008-09-19 (on taura, although
this is occurring on all machines that use the above optimization settings).

The abort message is:

Uncaught Mercury exception:
Software Error: code_gen.m: Unexpected: nondet model in det/semidet context
Stack dump not available in this grade.
TagsNo tags attached.
Attached Files? bug85.m (5,854) 2008-09-23 16:14
https://bugs.mercurylang.org/file_download.php?file_id=67&type=bug

Notes
(0000150)
juliensf   
2008-09-23 11:21   
The abort occurs during the following step:

% Generating low-level (LLDS) code for predicate `ll_backend.deep_profiling.coverage_prof_second_pass_goal'/7 mode 0

I've committed a workaround that forces the affected module to be compiled at -O2.
The bug does not occur at that optimization level.
(0000151)
juliensf   
2008-09-23 11:29   
In fact, this has nothing to do with --intermodule-optimisation. The bug occurs with -O3.
(0000152)
juliensf   
2008-09-23 16:14   
(Last edited: 2008-09-23 16:17)
I've added a test case for this one that is independent of the compiler.
Compile with: -O0 --deforestation -C

(0000153)
zs   
2008-09-23 18:45   
The body of the affected predicate has two switches followed by an if-then-else. Deforestation pushes the second switch and the if-then-else into each arm of the first switch, and then specializes the if-then-else. The problem is that in the process of specialization, it sets the determinism of the condition to nondet, when it should be semidet. The cause could be fact that, after propagating CoverageAfterKnown0 = CoverageAfterKnown1, it replaces the original test in the condition (CoverageAfterKnown1 = coverage_after_known) with a test on CoverageAfterKnown0, and thus updates the nonlocals set. It may think that this affects the determinism of the disjunction that is the condition, but in this case it doesn't.

The problem part of the HLDS dump is the following.

   ( % cannot_fail switch on `MaybeDPCoverageInfo'
      % MaybeDPCoverageInfo has functor maybe.no/0
      % nonlocals: CoverageAfterKnown0, GoalExpr0, CPOptions, IsMDProfInst, CoverageAfterKnown
      % determinism: multi
      ( % conjunction
        % nonlocals: GoalTrivial
        % determinism: det
        GoalTrivial = bug85.goal_is_nontrivial
        ,
        % nonlocals: CoverageAfterKnown0, GoalExpr0, CPOptions, IsMDProfInst, GoalTrivial, CoverageAfterKnown
        % determinism: multi
        (if
          % nonlocals: CoverageAfterKnown0, GoalExpr0, IsMDProfInst, GoalTrivial
          % determinism: nondet
          ( % disjunction
            % nonlocals: IsMDProfInst
            % determinism: semidet
            IsMDProfInst = bug85.goal_is_mdprof_inst
          ;
            % nonlocals: CoverageAfterKnown0
            % determinism: semidet
            CoverageAfterKnown0 = bug85.coverage_after_known
          ;
            % nonlocals: GoalTrivial
            % determinism: semidet
            GoalTrivial = bug85.goal_is_trivial
          ;
            % nonlocals: GoalExpr0
            % determinism: semidet
            ( % conjunction
              % nonlocals: GoalExpr0, V_42
              % determinism: semidet
              GoalExpr0 = bug85.conj(V_42, V_25)
              ,
              % nonlocals: V_42
              % determinism: semidet
              V_42 = bug85.plain_conj
            )
          )

Issue History
2008-09-23 09:44juliensfNew Issue
2008-09-23 11:21juliensfNote Added: 0000150
2008-09-23 11:29juliensfNote Added: 0000151
2008-09-23 16:14juliensfFile Added: bug85.m
2008-09-23 16:14juliensfNote Added: 0000152
2008-09-23 16:17juliensfNote Edited: 0000152
2008-09-23 18:45zsNote Added: 0000153