Skip to content

Commit

Permalink
[AMDGPULowerBufferFatPointers] Don't try to preserve flags for consta…
Browse files Browse the repository at this point in the history
…nt expressions

We expect all of these ConstantExpr ctors to fold away, don't try
to preserve flags, especially as the flags are not correct.
  • Loading branch information
nikic committed Jun 14, 2024
1 parent f1a29ec commit 1ceede3
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions llvm/lib/Target/AMDGPU/AMDGPULowerBufferFatPointers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -680,35 +680,28 @@ Constant *FatPtrConstMaterializer::materializeBufferFatPtrConst(Constant *C) {
report_fatal_error(
"Scalable vector or unsized struct in fat pointer GEP");
Constant *OffAccum = nullptr;
// Accumulate offsets together before adding to the base in order to
// preserve as many of the inbounds properties as possible.
for (auto [Arg, Multiple] : VariableOffs) {
Constant *NewArg = InternalMapper.mapConstant(*cast<Constant>(Arg));
NewArg = ConstantFoldIntegerCast(NewArg, OffTy, /*IsSigned=*/true, DL);
if (!Multiple.isOne()) {
if (Multiple.isPowerOf2()) {
NewArg = ConstantExpr::getShl(
NewArg,
CE->getIntegerValue(
OffTy, APInt(BufferOffsetWidth, Multiple.logBase2())),
/*hasNUW=*/InBounds, /*HasNSW=*/InBounds);
NewArg, CE->getIntegerValue(OffTy, APInt(BufferOffsetWidth,
Multiple.logBase2())));
} else {
NewArg =
ConstantExpr::getMul(NewArg, CE->getIntegerValue(OffTy, Multiple),
/*hasNUW=*/InBounds, /*hasNSW=*/InBounds);
NewArg = ConstantExpr::getMul(NewArg,
CE->getIntegerValue(OffTy, Multiple));
}
}
if (OffAccum) {
OffAccum = ConstantExpr::getAdd(OffAccum, NewArg, /*hasNUW=*/InBounds,
/*hasNSW=*/InBounds);
OffAccum = ConstantExpr::getAdd(OffAccum, NewArg);
} else {
OffAccum = NewArg;
}
}
Constant *NewConstOff = CE->getIntegerValue(OffTy, NewConstOffVal);
if (OffAccum)
OffAccum = ConstantExpr::getAdd(OffAccum, NewConstOff,
/*hasNUW=*/InBounds, /*hasNSW=*/InBounds);
OffAccum = ConstantExpr::getAdd(OffAccum, NewConstOff);
else
OffAccum = NewConstOff;
bool HasNonNegativeOff = false;
Expand Down

0 comments on commit 1ceede3

Please sign in to comment.