[llvm-dev] isHardwareLoopProfitable() called with empty assumption cache in hwloops pass

Janek Van Oirschot via llvm-dev llvm-dev at lists.llvm.org
Thu Mar 25 06:39:43 PDT 2021


> Just out of curiousity, can you perhaps tell more how you would like to persuade/force hardware loops with an assume? There are some options at the moment (but would apply to all loops in the compilation unit), don't think we e.g. looked into a pragma, so it sounds interesting. I guess this is a hint about the iteration count?

Yeah, basically hint about the iteration count so the user can emit hardware loops on a per-loop basis. We were also thinking about using pragmas (and I believe it would be a more user friendly way to emit hardware loops) but I noticed that I had most tools at hand (assumptioncache, computeKnownBits) to possibly get it working with assume intrinsics as an "easy" first step.

> As Sjoerd said, can we re-populate it?

I believe that after CGP all assume intrinsics will be gone so I don't think that will be possible (unless there's another way to find the assumptions and repopulate the assumptioncache). Moving the hardwareloops pass before CGP sounds like a possibility but I'm not sure about the impact of doing so (in terms of no. of hwloops emitted).

> And in the `CodeMetrics` class, when it calculates the instruction number, it will exclude the ephemeral values(llvm.assume related instructions) first, that's why we need assumption cache analysis.

I did notice that isHardwareLoopProfitable is also called from TTI's canSaveCmp in PPC which may explain the need of using the assumptioncache in isHardwareLoopProfitable.


Kind regards,
Janek van Oirschot

From: Zheng CZ Chen <czhengsz at cn.ibm.com>
Date: Thursday, 25 March 2021 at 10:50
To: Sam Parker <Sam.Parker at arm.com>, David Green <David.Green at arm.com>, Janek Van Oirschot <janekvo at graphcore.ai>, Sjoerd Meijer <Sjoerd.Meijer at arm.com>
Cc: "llvm-dev at lists.llvm.org" <llvm-dev at lists.llvm.org>
Subject: RE: isHardwareLoopProfitable() called with empty assumption cache in hwloops pass


The usage of `AssumptionCache` in PPC hardware loop was introduced in 0724fea2da637883f1461e12ff46d596a816f758

For PPC hardware loop pass, we want to make sure we will not convert some small loops into hardware loop. Small loop is identified by instruction number of the loop. So we used `CodeMetrics` class to calculate the instruction number.

And in the `CodeMetrics` class, when it calculates the instruction number, it will exclude the ephemeral values(llvm.assume related instructions) first, that's why we need assumption cache analysis.

I think it is ok to have empty `AssumptionCache`in PPC hardware loop pass as it is true that after CGP there is no ephemeral values any more.

But maybe it makes more sense to have other APIs for `CodeMetrics` class to calculate instruction number without `AssumptionCache`.

Thanks.

BRS//
Chen Zheng
Power Compiler Backend Developer


[Inactive hide details for Sam Parker ---2021/03/25 05:44:25 PM---Indeed, it's just there because the original PPC implementatio]Sam Parker ---2021/03/25 05:44:25 PM---Indeed, it's just there because the original PPC implementation used it. Looking back through the co

From: Sam Parker <Sam.Parker at arm.com>
To: Sjoerd Meijer <Sjoerd.Meijer at arm.com>, Janek Van Oirschot <janekvo at graphcore.ai>, "llvm-dev at lists.llvm.org" <llvm-dev at lists.llvm.org>
Cc: David Green <David.Green at arm.com>, "czhengsz at cn.ibm.com" <czhengsz at cn.ibm.com>
Date: 2021/03/25 05:44 PM
Subject: [EXTERNAL] Re: isHardwareLoopProfitable() called with empty assumption cache in hwloops pass

________________________________



Indeed, it's just there because the original PPC implementation used it. Looking back through the commits, I didn't move the pass into a different phase so either PPC has either never had a populated assumption cache or never noticed the change ZjQcmQRYFpfptBannerStart
This Message Is From an External Sender
This message came from outside your organization.
ZjQcmQRYFpfptBannerEnd
Indeed, it's just there because the original PPC implementation used it. Looking back through the commits, I didn't move the pass into a different phase so either PPC has either never had a populated assumption cache or never noticed the change when it was cleared.

As Sjoerd said, can we re-populate it?

As long as it runs after LSR, I can't immediately think of anything that would affect the Arm implementation (famous last words!) if we moved the transform a bit earlier in the pipeline.

Regards,
Sam

Sam Parker
Compilation Tools Engineer | Arm
. . . . . . . . . . . . . . . . . . . . . . . . . . .
Arm.com
________________________________

From: Sjoerd Meijer <Sjoerd.Meijer at arm.com>
Sent: 25 March 2021 09:32
To: Janek Van Oirschot <janekvo at graphcore.ai>; llvm-dev at lists.llvm.org <llvm-dev at lists.llvm.org>
Cc: Sam Parker <Sam.Parker at arm.com>; David Green <David.Green at arm.com>
Subject: Re: isHardwareLoopProfitable() called with empty assumption cache in hwloops pass

I can't imagine that being the intended behaviour. I don't think we have paid much attention to the assumption cache in the ARM implementation. Some parts of the hardware loop infrastructure were factored out from the initial PPC implementation, which I think explains it is there and used by PPC, but not in the ARM implementation. But perhaps Sam knows more.

I have never looked into the AssumptionCache, but I assume there's way to retrigger and repopulate it (after CGP)?

Just out of curiousity, can you perhaps tell more how you would like to persuade/force hardware loops with an assume? There are some options at the moment (but would apply to all loops in the compilation unit), don't think we e.g. looked into a pragma, so it sounds interesting. I guess this is a hint about the iteration count?

Cheers,
Sjoerd.
________________________________

From: Janek Van Oirschot <janekvo at graphcore.ai>
Sent: 24 March 2021 17:27
To: llvm-dev at lists.llvm.org <llvm-dev at lists.llvm.org>
Cc: Sam Parker <Sam.Parker at arm.com>; Sjoerd Meijer <Sjoerd.Meijer at arm.com>; David Green <David.Green at arm.com>
Subject: isHardwareLoopProfitable() called with empty assumption cache in hwloops pass

Hey all,

It seems that when HardwareLoops calls the isHardwareLoopProfitable TTI hook, it never has a populated AssumptionCache. Some debugging revealed that HardwareLoops runs during the PreISel phase for ARM and PPC. However, the CodeGenPrepare pass runs before PreISel and removes all assumes meaning that the AssumptionCache in HardwareLoops will end up empty.

From what I gather (and let me know if I'm wrong), only PPC uses the AssumptionCache in isHardwareLoopProfitable but only to aid in some cost analysis. I was wondering whether it's intended behaviour to have an empty AssumptionCache during HardwareLoops? I ask because I was looking into using assumes to persuade HardwareLoops into emitting hardware intrinsics for our (downstream) target.

Kind regards,
Janek van Oirschot


** We have updated our privacy policy, which contains important information about how we collect and process your personal data. To read the policy, please click here<http://www.graphcore.ai/privacy> **

This email and its attachments are intended solely for the addressed recipients and may contain confidential or legally privileged information.
If you are not the intended recipient you must not copy, distribute or disseminate this email in any way; to do so may be unlawful.

Any personal data/special category personal data herein are processed in accordance with UK data protection legislation.
All associated feasible security measures are in place. Further details are available from the Privacy Notice on the website and/or from the Company.

Graphcore Limited (registered in England and Wales with registration number 10185006) is registered at 107 Cheapside, London, UK, EC2V 6DN.
This message was scanned for viruses upon transmission. However Graphcore accepts no liability for any such transmission.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20210325/5f75275b/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.gif
Type: image/gif
Size: 106 bytes
Desc: image001.gif
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20210325/5f75275b/attachment-0001.gif>


More information about the llvm-dev mailing list