This is an archive of the discontinued LLVM Phabricator instance.

[Polly] Fix code generation of llvm.expect intrinsic
ClosedPublic

Authored by annanay25 on May 9 2017, 12:24 AM.

Details

Summary

At the time of code generation, an instruction with an llvm intrinsic is ignored in copyBB. However, if the value of the instruction is used later in the program, the value needs to be synthesized. However, this is causing some issues with the instructions being generated in a hoisted basic block.

Removing llvm.expect from the list of ignored intrinsics fixes this bug.

Diff Detail

Repository
rL LLVM

Event Timeline

annanay25 created this revision.May 9 2017, 12:24 AM
annanay25 retitled this revision from Fix code generation of llvm.expect intrinsic to [WIP] Fix code generation of llvm.expect intrinsic.May 9 2017, 12:32 AM
grosser edited edge metadata.May 9 2017, 10:39 PM

Hi Annay,

this change should include a test case.

Hi sir,

Actually, I was trying to incorporate the changes that Johannes sir suggested yesterday. I have temporarily made these changes, specifically for the llvm.expect intrinsic (it can be later extended to other intrinsics) but it seems to be causing some side effects. Specifically, the llvm.expect instruction is correctly code generated with this change, but the trunc statement following that is not. Will update shortly sir.

https://gist.github.com/annanay25/5c4f47ab96cba1f0220f49b455fb191b#file-tempblockgenerators-cpp-L9-L13

annanay25 updated this revision to Diff 98405.May 10 2017, 12:02 AM

Incorporated Johannes sir's suggestion. Works now.

Basically, changed the instruction to be code generated from

%e = llvm.expect(%f, ..)

to

%e = %f

BBMap should continue to be in VTV in trySynthesizeNewValue().
@grosser sir, if you could confirm this, I will remove the [WIP] and add a minimal test case.

No need to remove the llvm.expect globally. You can just skip it using BBMap:

BBMap[%e] = %f

The other possibility is to remove llvm.expect from isIgnoredIntrinsic. Polly does not change the value of %f, so it can be argued that the generated value is still the same.

annanay25 updated this revision to Diff 98876.May 12 2017, 11:36 PM
annanay25 retitled this revision from [WIP] Fix code generation of llvm.expect intrinsic to [Polly][WIP] Fix code generation of llvm.expect intrinsic.
annanay25 added a subscriber: pollydev.

Fixes code generation of llvm.expect clause.

By removing llvm.expect from the list of ignored intrinsics, we generate code for it in copyBB like a normal instruction. This mitigates the problem of synthesizing the statement along with all its dependences in a hoisted basic block.

Hi Annanay,

instead of commenting out the function, can you remove it. Also, can you please add a test case.

grosser requested changes to this revision.May 13 2017, 2:42 AM
This revision now requires changes to proceed.May 13 2017, 2:42 AM
annanay25 updated this revision to Diff 98910.May 13 2017, 11:13 PM
annanay25 edited edge metadata.
annanay25 retitled this revision from [Polly][WIP] Fix code generation of llvm.expect intrinsic to [Polly] Fix code generation of llvm.expect intrinsic.

Great. Looks good. Can you also update the commit message to summarize the discussions we had and to explain why we choose the solution now implemented.

annanay25 edited the summary of this revision. (Show Details)May 13 2017, 11:48 PM
This revision was automatically updated to reflect the committed changes.