This is an archive of the discontinued LLVM Phabricator instance.

[LICM] Infer proper alignment from loads during scalar promotion
ClosedPublic

Authored by reames on Feb 28 2019, 7:24 PM.

Details

Summary

This patch fixes an issue where we would compute an unnecessarily small alignment during scalar promotion when no store is not to be guaranteed to execute, but we've proven load speculation safety. Since speculating a load requires proving the existing alignment is valid at the new location (see Loads.cpp), we can use the alignment fact from the load.

For non-atomics, this is a performance problem. For atomics, this is a correctness issue, though an *incredibly* rare one to see in practice. For atomics, we might not be able to lower an improperly aligned load or store (i.e. i32 align 1). If such an instruction makes it all the way to codegen, we *may* fail to codegen the operation, or we may simply generate a slow call to a library function. The part that makes this super hard to see in practice is that the memory location actually *is* well aligned, and instcombine knows that. So, to see a failure, you have to have a) hit the bug in LICM, b) somehow hit a depth limit in InstCombine/ValueTracking to avoid fixing the alignment, and c) then have generated an instruction which fails codegen rather than simply emitting a slow libcall. All around, pretty hard to hit.

Diff Detail

Repository
rL LLVM

Event Timeline

reames created this revision.Feb 28 2019, 7:24 PM
asbirlea accepted this revision.Mar 1 2019, 9:56 AM

This LGTM.

lib/Transforms/Scalar/LICM.cpp
1934 ↗(On Diff #188840)

Nit: delete a "thus".

This revision is now accepted and ready to land.Mar 1 2019, 9:56 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptMar 1 2019, 10:45 AM