-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[ValueTracking] Improve Bitcast
handling to match SDAG
#125935
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
9383a35
34e0a81
60b5456
a8393f7
40a1864
0bdef18
d898cdd
aa34bd4
ac66a2a
801b08d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -1346,6 +1346,8 @@ static void computeKnownBitsFromOperator(const Operator *I, | |||||||||||||||
isa<ScalableVectorType>(I->getType())) | ||||||||||||||||
break; | ||||||||||||||||
|
||||||||||||||||
unsigned NumElts = DemandedElts.getBitWidth(); | ||||||||||||||||
bool IsLE = Q.DL.isLittleEndian(); | ||||||||||||||||
// Look through a cast from narrow vector elements to wider type. | ||||||||||||||||
// Examples: v4i32 -> v2i64, v3i8 -> v24 | ||||||||||||||||
unsigned SubBitWidth = SrcVecTy->getScalarSizeInBits(); | ||||||||||||||||
|
@@ -1364,7 +1366,6 @@ static void computeKnownBitsFromOperator(const Operator *I, | |||||||||||||||
// | ||||||||||||||||
// The known bits of each sub-element are then inserted into place | ||||||||||||||||
// (dependent on endian) to form the full result of known bits. | ||||||||||||||||
unsigned NumElts = DemandedElts.getBitWidth(); | ||||||||||||||||
unsigned SubScale = BitWidth / SubBitWidth; | ||||||||||||||||
APInt SubDemandedElts = APInt::getZero(NumElts * SubScale); | ||||||||||||||||
for (unsigned i = 0; i != NumElts; ++i) { | ||||||||||||||||
|
@@ -1376,10 +1377,32 @@ static void computeKnownBitsFromOperator(const Operator *I, | |||||||||||||||
for (unsigned i = 0; i != SubScale; ++i) { | ||||||||||||||||
computeKnownBits(I->getOperand(0), SubDemandedElts.shl(i), KnownSrc, Q, | ||||||||||||||||
Depth + 1); | ||||||||||||||||
unsigned ShiftElt = Q.DL.isLittleEndian() ? i : SubScale - 1 - i; | ||||||||||||||||
unsigned ShiftElt = IsLE ? i : SubScale - 1 - i; | ||||||||||||||||
Known.insertBits(KnownSrc, ShiftElt * SubBitWidth); | ||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
// Look through a cast from wider vector elements to narrow type. | ||||||||||||||||
// Examples: v2i64 -> v4i32 | ||||||||||||||||
if (SubBitWidth % BitWidth == 0) { | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess the missing case llvm-project/llvm/lib/Analysis/ValueTracking.cpp Lines 1295 to 1301 in 07fa6d1
|
||||||||||||||||
unsigned SubScale = SubBitWidth / BitWidth; | ||||||||||||||||
KnownBits KnownSrc(SubBitWidth); | ||||||||||||||||
APInt SubDemandedElts = | ||||||||||||||||
APIntOps::ScaleBitMask(DemandedElts, NumElts / SubScale); | ||||||||||||||||
computeKnownBits(I->getOperand(0), SubDemandedElts, KnownSrc, Q, | ||||||||||||||||
Depth + 1); | ||||||||||||||||
|
||||||||||||||||
Known.Zero.setAllBits(); | ||||||||||||||||
Known.One.setAllBits(); | ||||||||||||||||
for (unsigned i = 0; i != SubScale; ++i) { | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this was supposed to go up to NumElts, not SubScale. If one of the first SubScale elements are non-demanded but later ones are demanded this will miscompile. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! I've opened #145223 to reland this. |
||||||||||||||||
if (DemandedElts[i]) { | ||||||||||||||||
unsigned Shifts = IsLE ? i : NumElts - 1 - i; | ||||||||||||||||
unsigned Offset = (Shifts % SubScale) * BitWidth; | ||||||||||||||||
Known = Known.intersectWith(KnownSrc.extractBits(BitWidth, Offset)); | ||||||||||||||||
if (Known.isUnknown()) | ||||||||||||||||
break; | ||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
break; | ||||||||||||||||
} | ||||||||||||||||
case Instruction::SExt: { | ||||||||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.