This is an archive of the discontinued LLVM Phabricator instance.

[ConstantFold][SVE] Skip scalable vectors in ConstantFoldInsertElementInstruction.
ClosedPublic

Authored by huihuiz on Dec 3 2019, 2:00 PM.

Details

Summary

Should not constant fold insertelement instruction for scalable vector type.

Diff Detail

Event Timeline

huihuiz created this revision.Dec 3 2019, 2:00 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 3 2019, 2:00 PM
huihuiz added a comment.EditedDec 3 2019, 2:42 PM

current upstream crash with "void llvm::Value::doRAUW(llvm::Value *, llvm::Value::ReplaceMetadataUses): Assertion `New->getType() == getType() && "replaceAllUses of value with new value of different type!"' failed."

opt -S -instcombine test.ll

test.ll

define <vscale x 4 x i32> @f(i32 %val) {
  %i = insertelement <vscale x 4 x i32> undef, i32 1, i32 0
  ret <vscale x 4 x i32> %i
}

instcombine probably isn't the best place to stick a test for ConstantFold.cpp. Not sure where we're sticking tests for ConstantFold.cpp these days, though. Maybe test/Analysis/ConstantFolding/ is appropriate. (The directory name is actually referring to different code, but it's closer.)

llvm/lib/IR/ConstantFold.cpp
840

We could handle the special case of inserting zero into a zero vector. Not important, though.

llvm/test/Transforms/InstCombine/insertelement.ll
71

Tests involving non-constant operands don't really seem related.

huihuiz updated this revision to Diff 232009.Dec 3 2019, 4:10 PM

Addressed review feedback.

efriedma accepted this revision.Dec 3 2019, 4:23 PM

LGTM. But please wait a couple days before you merge in case anyone wants to comment on the API usage.

This revision is now accepted and ready to land.Dec 3 2019, 4:23 PM
huihuiz retitled this revision from [InstCombine][SVE] Skip scalable vectors in ConstantFoldInsertElementInstruction. to [ConstantFold][SVE] Skip scalable vectors in ConstantFoldInsertElementInstruction..Dec 3 2019, 5:17 PM
spatel added inline comments.Dec 5 2019, 10:50 AM
llvm/lib/IR/ConstantFold.cpp
836–837

It would be clearer to say:

// Do not iterate on scalable vector. 
// The number of elements is unknown at compile-time.
llvm/test/Analysis/ConstantFolding/insertelement.ll
2 ↗(On Diff #232009)

This should RUN with "-constprop" rather than "-instcombine".

huihuiz updated this revision to Diff 232424.Dec 5 2019, 11:48 AM
huihuiz marked 2 inline comments as done.

Thank you Sanjay!

spatel accepted this revision.Dec 5 2019, 12:46 PM

LGTM

This revision was automatically updated to reflect the committed changes.