[PATCH] Fix for CodeGenPrepare wrongly updating the map of sunk addresses

Andrea_DiBiagio at sn.scee.net Andrea_DiBiagio at sn.scee.net
Fri Apr 12 10:56:08 PDT 2013


Hello,

I'd like to contribute a patch to fix a problem in Pass CodeGen Prepare.

Method OptimizeMemoryInst is not always able to correctly update DenseMap
SunkAddrs by erasing no longer valid keys associated to Values which have
been deleted in memory.

When method OptimizeMemoryInst calls function 
`RecursivelyDeleteTriviallyDeadInstructions', potentially not all the
dead keys are erased from the map SunkAddrs.
Therefore, there are cases where map SunkAddrs is left in a inconsistent
state where buckets associated to keys of deleted Values are 
still considered to be valid.

This can be problematic for example in the following scenario where:
1. A new Instruction I created to replace the address expression for a 
   load or store instruction;
2. address of I is the same as a previously deleted Value
   pointed to by a key K of map SunkAddrs;
3. K is still a valid key in SunkAddrs.

CodeGenPrepare may think that occurrence of address I could be replaced
with the Value returned by SunkAddrs[I] which is however invalid.

PROPOSED FIX
------------
With this patch, CodeGenPrepare now uses a CallbackVH as the key of
map SunkAddrs. Each CallbackVH is able to monitor changes in the
state of a specific key Value. When a key is deleted by
method RecursivelyDeleteTriviallyDeadInstructions its associated
CallbackVH is notified and the corresponding entry in SunkAddrs
is correctly erased.
I also added an x86 specific test case that exposes the problem 
found in CodeGenPrepare.

Thanks!
-- Andrea Di Biagio




**********************************************************************
This email and any files transmitted with it are confidential and intended 
solely for the use of the individual or entity to whom they are addressed. 
If you have received this email in error please notify postmaster at scee.net
This footnote also confirms that this email message has been checked for 
all known viruses.
Sony Computer Entertainment Europe Limited
Registered Office: 10 Great Marlborough Street, London W1F 7LP, United 
Kingdom
Registered in England: 3277793
**********************************************************************

P Please consider the environment before printing this e-mail
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.diff
Type: application/octet-stream
Size: 5322 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130412/e311fe36/attachment.obj>


More information about the llvm-commits mailing list