[llvm-dev] -speculative-execution moving load before store

Friedman, Eli via llvm-dev llvm-dev at lists.llvm.org
Wed May 10 10:51:20 PDT 2017


On 5/9/2017 11:37 PM, Mikael Holmén via llvm-dev wrote:
> Hi,
>
> A few days ago I stumbled upon a problem where SpeculativeExecution
> changed the order of a load and a store to the same address.
>
> I wrote
>
>  https://bugs.llvm.org//show_bug.cgi?id=32964
>
> about it but no response there so far.
>
> In the input we have
>
>   store i8 0, i8* @i
>   %.pre = load i8, i8* @i
>
> and then in the output the load is moved so it's before the store 
> which clearly makes it load the wrong value.
>
> isSafeToSpeculativelyExecute happily says "true" for the load, and 
> there is a comment on isSafeToSpeculativelyExecute saying
>
>   /// This method can return true for instructions that read memory;
>   /// for such instructions, moving them may change the resulting value.
>
> And that is indeed the case in PR32964.
>
> How is this supposed to work?

Passes are supposed to check whether the moved instruction actually 
produces the right result.  As a short-term fix, you can just add a 
check for mayReadFromMemory().  If you want to do something fancier, 
MemorySSA provides a convenient interface to check aliasing.

-Eli

-- 
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project



More information about the llvm-dev mailing list