Opened 5 years ago

Last modified 22 months ago

#7378 new bug

Identical alts/bad divInt# code

Reported by: daniel.is.fischer Owned by:
Priority: normal Milestone:
Component: Compiler Version: 7.6.1
Keywords: Cc: pho@…, hackage.haskell.org@…, tom.schrijvers@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Runtime performance bug Test Case:
Blocked By: Blocking:
Related Tickets: #7360, #2132 Differential Rev(s):
Wiki Page:

Description

This may be the same as #7360, but it may also be a problem in the code generation for divInt#. I've reduced it to the following minimal test case:

When compiling

fun :: Int -> Int
fun i = i `div` 2

with ghc -O2 -funfolding-use-threshold=150, the generated core becomes

Div2.fun =
  \ (i_aeH :: GHC.Types.Int) ->
    case i_aeH of _ { GHC.Types.I# ww_aiV ->
    case GHC.Prim.># ww_aiV 0 of _ {
      GHC.Types.False ->
        case GHC.Prim.<# ww_aiV 0 of _ {
          GHC.Types.False -> GHC.Types.I# (GHC.Prim.quotInt# ww_aiV 2);
          GHC.Types.True ->
            GHC.Types.I#
              (GHC.Prim.-# (GHC.Prim.quotInt# (GHC.Prim.+# ww_aiV 1) 2) 1)
        };
      GHC.Types.True ->
        case GHC.Prim.<# ww_aiV 0 of _ {
          GHC.Types.False -> GHC.Types.I# (GHC.Prim.quotInt# ww_aiV 2);
          GHC.Types.True ->
            GHC.Types.I#
              (GHC.Prim.-# (GHC.Prim.quotInt# (GHC.Prim.+# ww_aiV 1) 2) 1)
        }
    }
    }

with two identical case alternatives, and in the True case, the next comparison is guaranteed to return False.

The generated core is good if the divisor is negative, though, so that speaks for taking a look at divInt#.

Change History (10)

comment:1 Changed 5 years ago by PHO

Cc: pho@… added

comment:2 Changed 5 years ago by simonpj

difficulty: Unknown
  • The nested comparison thing is covered by #2132.

  • The two identical alternatives should be combined; but they are too big for cheapEqExpr to combine. Maybe we should be willing to compare in a nested way.

comment:3 Changed 5 years ago by liyang

Cc: hackage.haskell.org@… added

comment:4 Changed 5 years ago by igloo

Milestone: 7.8.1

comment:5 Changed 4 years ago by thoughtpolice

Milestone: 7.8.37.10.1

Moving to 7.10.1

comment:6 Changed 3 years ago by TomSchrijvers

Cc: tom.schrijvers@… added

comment:7 Changed 3 years ago by thoughtpolice

Milestone: 7.10.17.12.1

Moving to 7.12.1 milestone; if you feel this is an error and should be addressed sooner, please move it back to the 7.10.1 milestone.

comment:8 Changed 2 years ago by thoughtpolice

Milestone: 7.12.18.0.1

Milestone renamed

comment:9 Changed 2 years ago by jstolarek

comment:10 Changed 22 months ago by thomie

Milestone: 8.0.1
Note: See TracTickets for help on using tickets.