This is an archive of the discontinued LLVM Phabricator instance.

[InstSimplify] Teach isUndefValue to understand const vector with both undef & poison
AbandonedPublic

Authored by aqjune on Apr 3 2021, 9:57 PM.

Details

Summary

A constant vector that has both undef & poison, e.g., <i8 undef, i8 poison>, isn't UndefValue.
This causes SimplifyQuery::isUndefValue to return false even if it is.
This patch teaches the function to recognize such form as well.

Diff Detail

Event Timeline

aqjune requested review of this revision.Apr 3 2021, 9:57 PM
aqjune created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptApr 3 2021, 9:57 PM
aqjune added inline comments.Apr 3 2021, 10:10 PM
llvm/include/llvm/Analysis/InstructionSimplify.h
146

Dropping null checks caused assertion failures from the following tests:

LLVM :: Transforms/InstCombine/icmp-vec-inseltpoison.ll
LLVM :: Transforms/InstCombine/icmp-vec.ll
LLVM :: Transforms/InstCombine/select.ll
LLVM :: Transforms/InstCombine/sub.ll
LLVM :: Transforms/InstCombine/vec_shuffle-inseltpoison.ll
LLVM :: Transforms/InstCombine/vec_shuffle.ll
LLVM :: Transforms/InstSimplify/2011-09-05-InsertExtractValue.ll
LLVM :: Transforms/InstSimplify/pr33957.ll

I investigated a few of them and they were mainly due to ConstExpr having vector types.
But I have no idea whether adding !isa<ConstantExpr>(C) is enough to drop the null check... :/

nikic added a comment.Apr 4 2021, 1:56 AM

This problem isn't really limited to this one function in InstSimplify. Might it make sense to adjust UndefValue to actually represent such constants? We'd have to add a bitmask to it that indicates which values are poison.

This problem isn't really limited to this one function in InstSimplify. Might it make sense to adjust UndefValue to actually represent such constants? We'd have to add a bitmask to it that indicates which values are poison.

Hi,
There is ConstantStruct as well, so to make support that case UndefValue needs to store individual elements, I guess.

What do you think about updating m_Undef pattern matcher to recognize constants like <undef, poison> & replacing isa<UndefValue>(V) with match(V, m_Undef())?
The benefit is that we don't need to add to UndefValue the data structures ConstantAggregate is having.

p.s: BTW, ConstantStruct::get and ConstantArray::getImpl are not returning poison even if all elements are poison. I'll make a commit that applies the change that was made to ConstantVector::getImpl in the past.

This problem isn't really limited to this one function in InstSimplify. Might it make sense to adjust UndefValue to actually represent such constants? We'd have to add a bitmask to it that indicates which values are poison.

Hi,
There is ConstantStruct as well, so to make support that case UndefValue needs to store individual elements, I guess.

What do you think about updating m_Undef pattern matcher to recognize constants like <undef, poison> & replacing isa<UndefValue>(V) with match(V, m_Undef())?
The benefit is that we don't need to add to UndefValue the data structures ConstantAggregate is having.

p.s: BTW, ConstantStruct::get and ConstantArray::getImpl are not returning poison even if all elements are poison. I'll make a commit that applies the change that was made to ConstantVector::getImpl in the past.

+1 to fixing matcher

aqjune added a comment.Apr 8 2021, 9:10 AM

I made https://reviews.llvm.org/D100122 to show how the patch would look like if m_Undef is fixed instead.

I'm about to land D100122 instead - https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=29445 is waiting.
We can revisit this issue if fixing UndefValue is necessary.

aqjune abandoned this revision.Apr 17 2021, 8:15 PM