Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 5,255
    • Issues 5,255
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 562
    • Merge requests 562
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell CompilerGlasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #8832
Closed
Open
Issue created Mar 01, 2014 by Herbert Valerio Riedel@hvr🕺Maintainer

Constant-folding regression wrt `clearBit (bit 0) 0 `

While implementing zeroBits (see [83bd2f5fc7e/base]) I noticed that constant folding of the expression clearBit (bit 0) 0 regressed (and improved at the same time) from GHC 7.6.3 to GHC 7.8.1, specifically, the following module

{-# LANGUAGE CPP #-}

module M where

import Data.Bits
import Data.Int
import Data.Word

#define T(s,T) \
s :: T ; \
s = clearBit (bit 0) 0 ; \

T(i,Int)
T(i8,Int8)
T(i16,Int16)
T(i32,Int32)
T(i64,Int64)

T(w,Word)
T(w8,Word8)
T(w16,Word16)
T(w32,Word32)
T(w64,Word64)

T(z,Integer)

compiled with GHC 7.8.1RC2 results in the following Core output:

-- GHC 7.8.1RC2

i = I# (andI# 1 (notI# 1))

i8 = I8# 0
i16 = I16# 0
i32 = I32# 0
i64 = I64# 0

w = W# (__word 0)
w8 = W8# (__word 0)

w16 = W16# (__word 0)
w32 = W32# (__word 0)
w64 = W64# (__word 0)

z2 = $w$cbit 0
z1 = complementInteger z2
z = andInteger z2 z1

Thus, i and z are not properly constant-folded in GHC 7.8.1RC2. With GHC 7.6.3, however, i and z were properly folded to 0:

-- GHC 7.6.3

i = I# 0

i8 =
  case $fBitsInt8_$cbit i of _ { I8# x#_aDf ->
  case $fBitsInt8_$cbit i of _ { I8# x#1_aDr ->
  I8#
    (word2Int#
       (and#
          (int2Word# x#_aDf)
          (xor# (int2Word# x#1_aDr) (__word 18446744073709551615))))
  }
  }

i16,i32,i64 -- equivalent to i8

w = W# (__word 0)

w8 =
  case $fBitsWord8_$cbit i of _ { W8# x#_aEV ->
  case $fBitsWord8_$cbit i of _ { W8# x#1_aF5 ->
  W8# (and# x#_aEV (xor# x#1_aF5 (__word 255)))
  }
  }

w16,w32,w64 -- equivalent to w8

z = __integer 0
Trac metadata
Trac field Value
Version 7.8.1-rc2
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking