two: Optimize computation of idx2 further - #530
Conversation
This reduces the core size for the inner loop of two by 10 terms.
|
To my surprise, this actually seems to make Before: After: (This is with GHC-9.12.2 on a ThinkPad with an Intel i5-8265U CPU) I don't understand why, yet. |
|
Core, STG, Cmm and ASM all look slightly improved. I will run the benchmarks on a different machine too. |
|
Interesting. Could you explain how this works? Also, what's the Core look like? I wonder if the new one made branch prediction less reliable or if it's just alignment nonsense. |
|
So
Here's the Core diff for Rec {
--- RHS size: {terms: 105, types: 165, coercions: 0, joins: 0/2}
+-- RHS size: {terms: 95, types: 165, coercions: 0, joins: 0/2}
$wgo
:: forall k v s.
Int#
@@ -11131,18 +11131,18 @@ $wgo
(t2 :: HashMap k v)
(eta [OS=OneShot] :: State# s) ->
let {
- bp2 :: Word#
+ bp2# :: Word#
[LclId]
- bp2
+ bp2#
= uncheckedShiftL#
1## (word2Int# (and# (uncheckedShiftRL# ww2 ww) 31##)) } in
let {
- bp1 :: Word#
+ bp1# :: Word#
[LclId]
- bp1
+ bp1#
= uncheckedShiftL#
1## (word2Int# (and# (uncheckedShiftRL# ww1 ww) 31##)) } in
- case eqWord# bp1 bp2 of {
+ case eqWord# bp1# bp2# of {
__DEFAULT ->
case k1 of conrep { __DEFAULT ->
case newSmallArray#
@@ -11150,20 +11150,12 @@ $wgo
of
{ (# ipv, ipv1 #) ->
case writeSmallArray#
- @Lifted
- @s
- @(HashMap k v)
- ipv1
- (<#
- (word2Int# (and# (uncheckedShiftRL# ww1 ww) 31##))
- (word2Int# (and# (uncheckedShiftRL# ww2 ww) 31##)))
- t2
- ipv
+ @Lifted @s @(HashMap k v) ipv1 (ltWord# bp1# bp2#) t2 ipv
of s'
{ __DEFAULT ->
case unsafeFreezeSmallArray# @Lifted @s @(HashMap k v) ipv1 s' of
{ (# ipv2, ipv3 #) ->
- (# ipv2, or# bp1 bp2, ipv3 #)
+ (# ipv2, or# bp1# bp2#, ipv3 #)
}
}
}
@@ -11177,7 +11169,7 @@ $wgo
{ (# ipv, ipv1 #) ->
case unsafeFreezeSmallArray# @Lifted @s @(HashMap k v) ipv1 ipv of
{ (# ipv2, ipv3 #) ->
- (# ipv2, bp1, ipv3 #)
+ (# ipv2, bp1#, ipv3 #)
}
}
}I wouldn't expect much of a speedup from this change, since the operations avoided are very cheap, but I didn't expect a slow-down. |
This reduces the core size for the inner loop of two by 10 terms.