This is an archive of the discontinued LLVM Phabricator instance.

[ConstantFold][SVE] Fix constant folding for scalable vector binary operations.
ClosedPublic

Authored by huihuiz on Dec 12 2019, 4:59 PM.

Details

Summary

Scalable vector should not be evaluated element by element.
Add support to handle scalable vector UndefValue.

Diff Detail

Event Timeline

huihuiz created this revision.Dec 12 2019, 4:59 PM

Similar issue , current upstream crash at 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 -constprop add.ll -o -

add.ll

define <vscale x 8 x i16> @add() {
  %r = add <vscale x 8 x i16> undef, undef
  ret <vscale x 8 x i16> %r
}

I will also be moving other sve tests under test/Analysis/ConstantFolding/ to vscale.ll

I'd prefer to handle all the issues in ConstantFoldBinaryInstruction as one review, I think.

Hang on a bit.
Let me see if I can find more issues in ConstantFoldBinaryInstruction.

sdesmalen added inline comments.Dec 13 2019, 4:32 AM
llvm/lib/IR/ConstantFold.cpp
1019

nit: maybe move the subexpression

C1->getType()->isVectorTy() && C1->getType()->getVectorIsScalable()

to a separate IsScalableVector variable, so that this expression is easier to read?

lebedev.ri resigned from this revision.Jan 3 2020, 11:25 PM
huihuiz updated this revision to Diff 240975.Jan 28 2020, 12:54 PM
huihuiz marked an inline comment as done.
huihuiz edited the summary of this revision. (Show Details)

Apologies for the delay, was on vacation, also got caught up with a work project in the past two weeks.

There is more we can do for scalable vector for ConstantFoldBinaryInstruction.
E.g., Constant fold binary op with constant splats, refer to https://reviews.llvm.org/D71712

<binop> (<vty> splat(<ty> <C1>)),
                (<vty> splat(<ty> <C2>))
==>  <vty> splat (<ty> <binop> (C1, C2))

Enable this will require changing API of ConstantVector::getSplat() to take in ElementCount for number of elements.
Probably better to do in a separate patch.

For this patch, we might want to focus on not iterating over scalable vectors.

efriedma accepted this revision.Jan 28 2020, 1:32 PM

LGTM

llvm/test/Analysis/ConstantFolding/vscale.ll
1

You can drop the first line, since you edited the test by hand.

This revision is now accepted and ready to land.Jan 28 2020, 1:32 PM
This revision was automatically updated to reflect the committed changes.