This is an archive of the discontinued LLVM Phabricator instance.

[InstSimplify] Support constant folding to vector of pointers
ClosedPublic

Authored by bruno on Oct 16 2014, 4:32 PM.

Details

Summary

ConstantFolding crashes when trying to InstSimplify the following load:

@a = private unnamed_addr constant %mst {

i8* inttoptr (i64 -1 to i8*),
i8* inttoptr (i64 -1 to i8*)}, align 8

%x = load <2 x i8*>* bitcast (%mst* @a to <2 x i8*>*), align 8

This patch fix this by adding support to this type of folding:

%x = load <2 x i8*>* bitcast (%mst* @a to <2 x i8*>*), align 8

> gets folded to:

%x = <2 x i8*> <i8* inttoptr (i64 -1 to i8*), i8* inttoptr (i64 -1 to i8*)>

Diff Detail

Event Timeline

bruno updated this revision to Diff 15054.Oct 16 2014, 4:32 PM
bruno retitled this revision from to [InstSimplify] Support constant folding to vector of pointers.
bruno updated this object.
bruno edited the test plan for this revision. (Show Details)
bruno added reviewers: arsenm, chandlerc, bkramer.
bruno set the repository for this revision to rL LLVM.
bruno added a subscriber: Unknown Object (MLST).
arsenm added inline comments.Oct 17 2014, 11:44 AM
lib/Analysis/ConstantFolding.cpp
59

Comment should be capitalized.

Why do you need this check on the isAllOnesValue() and not the isNullValue() case?

200

Slightly misleading comment? This bitcast isn't allowed and this needs to be an inttoptr

201–202

You don't need to do this check to get the type size yourself. TD.getTypeSizeInBits checks the pointeriness for you

test/Transforms/InstSimplify/vector_ptr_bitcast.ll
7–9

Another testcase that uses different sized pointers that require a trunc might be useful. Also one that uses constants other than -1

13–14

Test should probably do something with this so there is something to check other than deleting all of the code

bruno added inline comments.Oct 20 2014, 11:54 AM
lib/Analysis/ConstantFolding.cpp
59

Because getNullValue knows how to handle a PointerTyID, through ConstantPointerNull. There isn't a "ConstantPointerOnes" and IMO that would also not make much sense.

bruno updated this revision to Diff 15147.Oct 20 2014, 11:55 AM

Added a new patch addressing the comments from Matt

arsenm accepted this revision.Oct 21 2014, 2:34 PM
arsenm edited edge metadata.

LGTM

This revision is now accepted and ready to land.Oct 21 2014, 2:34 PM
bruno closed this revision.Oct 22 2014, 5:30 AM

Thanks,

Committed in r220380.