Force GC calls out of the straight line execution path

Hi, I noticed in the generated code (llvm as well as native) that in some cases the GC calls are in the straight path and the regular code is out of the straight line path. Like this: => 0x408fc0: lea 0x30(%r12),%rax => 0x408fc5: cmp 0x358(%r13),%rax => 0x408fcc: jbe 0x408fe9 # notice jbe instead of ja i.e. branch taken in normal case I tried to count in how many cases its happening in my executable and found that its only a small percentage (4-6%) of cases but those cases include the code which runs 99% of the time in my benchmark. Though it does not make a whole lot of difference but the difference is perceptible and especially when it is in a tight loop. Is it possible to somehow force all the GC calls out of the line during code generation? Has it been thought/discussed before? -harendra

Hi Harendra,
Would it be possible for you to provide a minimal example that compiles to such
assembly? It's hard to tell if this is an easy case.
Also, just to make sure, you're using -O, right? (I'm not sure if we have a
related transformation enabled with -O but just to make sure...)
2016-06-13 7:23 GMT-04:00 Harendra Kumar
Hi,
I noticed in the generated code (llvm as well as native) that in some cases the GC calls are in the straight path and the regular code is out of the straight line path. Like this:
=> 0x408fc0: lea 0x30(%r12),%rax => 0x408fc5: cmp 0x358(%r13),%rax => 0x408fcc: jbe 0x408fe9 # notice jbe instead of ja i.e. branch taken in normal case
I tried to count in how many cases its happening in my executable and found that its only a small percentage (4-6%) of cases but those cases include the code which runs 99% of the time in my benchmark. Though it does not make a whole lot of difference but the difference is perceptible and especially when it is in a tight loop.
Is it possible to somehow force all the GC calls out of the line during code generation? Has it been thought/discussed before?
-harendra
_______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs

Hi Ömer,
I just checked and I do not see this behavior in 8.0.1 native code, it is
only seen in 7.10.3. So I guess this got fixed in 8.0.
How about the llvm generated code? Can we control this behavior for llvm
generated code as well? I first noticed this in llvm generated code with
ghc-7.10.3. I do not yet have llvm-3.7 installed to verify the same on
8.0.1.
-harendra
On 13 June 2016 at 18:04, Ömer Sinan Ağacan
Hi Harendra,
Would it be possible for you to provide a minimal example that compiles to such assembly? It's hard to tell if this is an easy case.
Also, just to make sure, you're using -O, right? (I'm not sure if we have a related transformation enabled with -O but just to make sure...)
Hi,
I noticed in the generated code (llvm as well as native) that in some cases the GC calls are in the straight path and the regular code is out of the straight line path. Like this:
=> 0x408fc0: lea 0x30(%r12),%rax => 0x408fc5: cmp 0x358(%r13),%rax => 0x408fcc: jbe 0x408fe9 # notice jbe instead of ja i.e. branch taken in normal case
I tried to count in how many cases its happening in my executable and found that its only a small percentage (4-6%) of cases but those cases include
2016-06-13 7:23 GMT-04:00 Harendra Kumar
: the code which runs 99% of the time in my benchmark. Though it does not make a whole lot of difference but the difference is perceptible and especially when it is in a tight loop.
Is it possible to somehow force all the GC calls out of the line during code generation? Has it been thought/discussed before?
-harendra
_______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs

Harendra Kumar
Hi Ömer,
I just checked and I do not see this behavior in 8.0.1 native code, it is only seen in 7.10.3. So I guess this got fixed in 8.0.
How about the llvm generated code? Can we control this behavior for llvm generated code as well? I first noticed this in llvm generated code with ghc-7.10.3. I do not yet have llvm-3.7 installed to verify the same on 8.0.1.
Indeed that may be the difference. It looks like the LLVM code generator currently ignores the expected value provided by the C-- representation. This is pretty straightforward to fix; see D2339 [1]. Cheers, - Ben [1] https://phabricator.haskell.org/D2339

On 17 June 2016 at 17:30, Ben Gamari
Awesome! -harendra
participants (3)
-
Ben Gamari
-
Harendra Kumar
-
Ömer Sinan Ağacan