This is an archive of the discontinued LLVM Phabricator instance.

[TargetLowering] fix isConstTrueVal to account for build vector truncation
ClosedPublic

Authored by spatel on Apr 25 2017, 2:23 PM.

Details

Summary

Build vectors have magical truncation powers, so we have things like this:

v4i1 = BUILD_VECTOR Constant:i32<1>, Constant:i32<1>, Constant:i32<1>, Constant:i32<1>
v4i16 = BUILD_VECTOR Constant:i32<1>, Constant:i32<1>, Constant:i32<1>, Constant:i32<1>

If we don't truncate the splat node returned by getConstantSplatNode(), then we won't find truth when ZeroOrNegativeOneBooleanContent is the rule.

Note: I was hoping that ISD::isConstantSplatVector() would have worked here, but it doesn't because it has this bitsize check which I don't understand yet:

return BV->isConstantSplat(SplatVal, SplatUndef, SplatBitSize, HasUndefs) &&
       EltVT.getSizeInBits() >= SplatBitSize;

Diff Detail

Repository
rL LLVM

Event Timeline

spatel created this revision.Apr 25 2017, 2:23 PM
efriedma edited edge metadata.Apr 25 2017, 3:11 PM

I was hoping that ISD::isConstantSplatVector() would have worked here, but it doesn't

I'd rather fix this, unless you think the check is important for some reason.

I was hoping that ISD::isConstantSplatVector() would have worked here, but it doesn't

I'd rather fix this, unless you think the check is important for some reason.

BuildVectorSDNode::isConstantSplat() is broken for a truncating BV. For the bool vec cases we're seeing here, it's claiming that the splat val is a 4-bit APInt with value 15.

I'm not sure if it should just assert that the input vector has at least byte-sized elements:

while (VecWidth > 8) {

(it takes endianness as a param too)
or if it needs to take truncation into account.

If I just change that loop check to (VecWidth > 2), we crash several regression tests.
So I'd like to fix it too, but I'd rather not gate this patch on that if that's alright?

efriedma accepted this revision.Apr 25 2017, 6:25 PM

Sure. LGTM.

This revision is now accepted and ready to land.Apr 25 2017, 6:25 PM

Thanks, Eli! I added some FIXME notes in:
rL301403

I'll commit this, then update D31944, then see if I can make sense of our splat detection. :)

This revision was automatically updated to reflect the committed changes.