Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bitcode files do not preserve order of use lists #6052

Closed
llvmbot opened this issue Dec 4, 2009 · 8 comments
Closed

bitcode files do not preserve order of use lists #6052

llvmbot opened this issue Dec 4, 2009 · 8 comments
Assignees
Labels
bugzilla Issues migrated from bugzilla llvm:bitcode

Comments

@llvmbot
Copy link
Collaborator

llvmbot commented Dec 4, 2009

Bugzilla Link 5680
Resolution FIXED
Resolved on Apr 14, 2015 16:45
Version trunk
OS All
Reporter LLVM Bugzilla Contributor
CC @asl,@atrick,@lattner,@dexonsmith,@sunfishcode,@nlewycky,@stoklund

Extended Description

The order of entries in use lists is deterministic but that order is not preserved in bitcode files. Serializing/deserializing the IR to a bitcode file in between passes may change the behavior of those passes if they depend on the order of use lists. This is a problem for bugpoint and for manual debugging as well.

I ran into this while trying to track down a performance problem in llvm-gcc. Writing a bitcode file and running llc produced slightly different results that prevented me from reproducing the performance issues. I tracked this down to CodeGenPrepare splitting critical edges by iterating over the basic block predecessor list and selecting the first suitable edge to split. The order of predecessors was different in llc than in llvm-gcc, which caused a different edge to be split. The problem applies to all use lists, not just basic block predecessors.

It would be good to add information to the bitcode files to preserve the use list order, at least as an option for debugging.

It would also be good to have a way to keep that same information in llvm assembly files so that disassembling a bitcode file preserves the information.

@llvmbot
Copy link
Collaborator Author

llvmbot commented Dec 4, 2009

assigned to @dexonsmith

@stoklund
Copy link
Mannequin

stoklund mannequin commented Dec 4, 2009

The critical edge splitting in PHIElimination should be independent of block ordering, except for the numbering of the new blocks. The numbering is used as a third-level sorting key by the copy coalescer, so you could get different results there.

I have experimented with removing edge splitting completely from CodeGenPrepare. It mostly works, except for a few test cases whose performance suffer.

But it is probably difficult to be completely order independent, so your suggestions are good.

@nlewycky
Copy link
Contributor

nlewycky commented Dec 7, 2009

edge order passes proof of concept
I disagree that we should store the use-list orderings in the .bc and .ll files. I do agree that there is a distinct need to have access to this data for testcases and whatnot. I also think that we should be able to write passes that are idempotent across changes to the order of the use-list, like we write passes which work the same regardless of the memory addresses.

I've written a patch which creates lib/Transforms/IPO/EdgeOrder.cpp that provides three passes. The first is -scramble-edges which runs std::random_shuffle over the ordering of the use-list for every value. Every pass (and .bc and .ll output) should behave the same when -scramble-edges is inserted.

The other two passes load and save use list ordering information to disk. They do this with a modified ValueEnumerator that assigns the same numbers to all reachable Values, even across .bc boundaries. You can run 'opt -edge-order-outfile=filename -save-edge-order' to produce a use-list information file and 'opt -edge-order-infile=filename -load-edge-order' to load it back in.

Now please understand, this patch is ONLY a proof of concept. It's ugly, it violates LLVM style, it's not factored properly, its file format is stupid, etc. Please PLEASE please understand ALL of the XXX comments in EdgeOrder.cpp before trying to use it.

One final thing: in an average Module there are users which don't exist in the .bc file. The bitcode reader may create ConstantExpr's (that use GlobalValues) which don't end up in the final Module. This means that you can't preserve them in a .bc file, at least not without doing something more drastic. See the comments about GV->removeDeadConstantUsers() in the patch.

@lattner
Copy link
Collaborator

lattner commented Dec 7, 2009

Dependence on use list order is very pervasive throughout the compiler, for example, the order of pred_iterator depends on it. It is deterministic and not a problem, except that it doesn't get serialized out.

@dexonsmith
Copy link
Mannequin

dexonsmith mannequin commented Jul 21, 2014

I'm actively investigating this now, and just posted a summary of my current understanding (and plan) to llvmdev:

http://lists.cs.uiuc.edu/pipermail/llvmdev/2014-July/074966.html

@dexonsmith
Copy link
Mannequin

dexonsmith mannequin commented Aug 2, 2014

The bitcode side of this is in tree and working (commits to date at the end of this comment), save for one patch that's under review 1. Need to do some profiling, but otherwise this looks done.

r213824 = 5667cf2fef6816bb384c36464938608051a1b7c9
r213836 = 117dff7
r213866 = 6d469808a046185a46ec8790f3a104c47ffa6c66
r213945 = cb9adb363fad8d9e82dbd323470b91852d299cf5
r213946 = d8d3b4d
r213947 = deb8e30
r213953 = 17cb4cb
r213957 = 2602b66
r214121 = 31e6dbf
r214122 = beb0ac5
r214123 = 0aed6e7
r214125 = bd24fe8
r214128 = 8a4d11e
r214135 = f575ec4
r214144 = a784589
r214155 = 2c9dac0
r214156 = 15f92a3
r214157 = 994af14
r214184 = 34fa697
r214187 = 52f23be
r214212 = 49d1690
r214213 = bcb3a41
r214224 = f805325
r214241 = abf3c77
r214242 = 9b9c195
r214243 = 04bcdf1
r214249 = 70fec68
r214260 = 56a165c
r214264 = f8b862d
r214270 = c128f3b
r214271 = cd29d80
r214313 = e188fa6
r214317 = 4a9efda
r214318 = 89c4197
r214320 = 8dc3e30
r214321 = 43b54db
r214365 = d321cdf
r214368 = e5ae09b
r214417 = 9d65d37
r214419 = 94f7c7a
r214556 = 2e9b60a
r214558 = fc15e8a
r214559 = cf8b959
r214563 = 865919d
r214570 = 147851e
r214581 = 1526278
r214584 = 7df1db5
r214587 = 236c1ac
r214592 = b2b0ad4
r214594 = 99a43c2
r214595 = 4277019
r214596 = 1d31691

@dexonsmith
Copy link
Mannequin

dexonsmith mannequin commented Aug 5, 2014

LTO bitcode from tablegen (7.2MB) passes verify-uselistorder (with the global ctors patch 1 applied).

@dexonsmith
Copy link
Mannequin

dexonsmith mannequin commented Apr 14, 2015

I turned this on by default in r234510, then reversed course 1 with r234919, r234920 (clang), and r234921. Also cleaned up the output of verify-uselistorder in r234929. Now it's on by default for clang -save-temps, clang -emit-llvm, and for all the LLVM tools I found that output bitcode.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 3, 2021
augusto2112 pushed a commit to augusto2112/llvm-project that referenced this issue Jan 21, 2023
…e1b2b4ecf4cd658019d867

[lldb] Re-enable xmm/ymm/zmm tests with the system debugserver
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla llvm:bitcode
Projects
None yet
Development

No branches or pull requests

3 participants