This is an archive of the discontinued LLVM Phabricator instance.

[InstSimplify] Fix a scalable-vector crash
ClosedPublic

Authored by frasercrmck on Jun 22 2023, 8:57 AM.

Details

Summary

D143505 fixed/simplified folding of operations with SNaN operands. In
doing so it introduced a crash when handling scalable vector types,
wherein the scalable-vector ConstantVector was cast to a ConstantFP.

Since we know by that point in the code that if we've found a NaN, we're
dealing with a scalable-vector splat (as there are no other kinds of
scalable-vector constant for which that holds), we can grab the splatted
value and re-use the existing code, which will automatically splat the
new NaN back to a scalable vector for us.

Diff Detail

Event Timeline

frasercrmck created this revision.Jun 22 2023, 8:57 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 22 2023, 8:57 AM
frasercrmck requested review of this revision.Jun 22 2023, 8:57 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 22 2023, 8:57 AM
arsenm added inline comments.Jun 28 2023, 4:55 AM
llvm/lib/Analysis/InstructionSimplify.cpp
5471

Why is this down here and not another dyn_cast<ScalableVector> after the FixedVectorType case?

llvm/test/Transforms/InstSimplify/fp-nan.ll
59

Add some scalable vector tests with other FP classes?

frasercrmck added inline comments.Jun 28 2023, 5:50 AM
llvm/lib/Analysis/InstructionSimplify.cpp
5471

I did it here because the lines above:

if (!In->isNaN())
    return ConstantFP::getNaN(Ty);

Work on scalable vectors, so we don't have to re-implement that part. note how the fixed-vector case does do that.

llvm/test/Transforms/InstSimplify/fp-nan.ll
59

Ah good point. I initially left those out because I thought those fixed-vector tests were there to check non-splat behaviour (which we can't do in scalable vectors) but yeah now I see it's also checking different FP classes.

I'll add the appropriate scalable tests (one for each class below, I suppose)

  • extend scalable vector testing
arsenm accepted this revision.Jun 28 2023, 7:22 AM
This revision is now accepted and ready to land.Jun 28 2023, 7:22 AM
This revision was automatically updated to reflect the committed changes.