This is an archive of the discontinued LLVM Phabricator instance.

Extend load/store type canonicalization to handle unordered operations
ClosedPublic

Authored by reames on Apr 21 2016, 11:52 AM.

Details

Summary

The patch itself is pretty straight forward. I wanted to get a second set of eyes on this mostly to make sure there isn't some cornercase where the type of a unordered load or store effects the lowering in a semantic way. I'm not aware of any, but this is the change which would find them if they exist. :)

p.s. I believe we now support all power of two types for atomic loads and stores. If not, I'll need to add a restriction to the patch. Anyone know of a case?

Diff Detail

Event Timeline

reames updated this revision to Diff 54555.Apr 21 2016, 11:52 AM
reames retitled this revision from to Extend load/store type canonicalization to handle unordered operations.
reames updated this object.
reames added reviewers: jfb, chandlerc, jyknight.
reames added a subscriber: llvm-commits.
jfb edited edge metadata.Apr 21 2016, 1:10 PM

I don't think it matters but would rather ask: there's no case where a less-than-naturally-aligned atomic would matter? I'm specifically thinking of an example such as:

%v = load atomic i32, i32* %p unordered, align 2
%c = bitcast i32 to float
%s = add float %c, 1.0

Could this new code be leading backends to generate bad code? I think not, LMK if you think otherwise.

lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
330

Add assert(!LI.isVolatile() && "volatile unhandled here") here and below, makes it less likely to break in the future.

test/Transforms/InstCombine/atomic.ll
207

; TODO: probably also legal in this case

jfb added a comment.Apr 21 2016, 1:10 PM

Forgot to say: lgtm after these comments.

reames accepted this revision.Apr 22 2016, 2:03 PM
reames added a reviewer: reames.
This revision is now accepted and ready to land.Apr 22 2016, 2:03 PM
reames closed this revision.Apr 22 2016, 2:05 PM

This landed as 267210.

@JF - There shouldn't be any code generation differences for two types with the same alignment, even if that alignment isn't natural.

jfb added a comment.Apr 22 2016, 2:19 PM

This landed as 267210.

@JF - There shouldn't be any code generation differences for two types with the same alignment, even if that alignment isn't natural.

Many ISAs have different load / store instructions for FP versus integer, and some behave differently. Going from FP to integer in this case (no intervening use) seems fine, but I do think it's likely to change code generation (unless the backend already performed the same transformation).

chandlerc edited edge metadata.Apr 23 2016, 12:46 PM
In D19381#409561, @jfb wrote:

This landed as 267210.

@JF - There shouldn't be any code generation differences for two types with the same alignment, even if that alignment isn't natural.

Many ISAs have different load / store instructions for FP versus integer, and some behave differently. Going from FP to integer in this case (no intervening use) seems fine, but I do think it's likely to change code generation (unless the backend already performed the same transformation).

The patch is good of course, but I think JF is onto something here. Specifically, it would be good to make sure that backends which implement reasonable lowering for under-aligned atomic load and store of an integer also reasonably lower under-aligned atomic load and store of a floating point value. And the same for pointers.

I'm worried there are targets that have never had anyone test their ability to lower a 1-byte aligned atomic float or atomic pointer, and will need to be updated in the face of this.