forked from OSchip/llvm-project
[IRBuilder] Remove positivity check from CreateAlignmentAssumption()
Summary: An alignment should be non-zero positive power-of-two, anything and everything else is UB. We should not have that check for all these prerequisites here, it's just UB. Also, that was likely confusing middle-end passes. While there, `CreateIntCast()` should be called with `/*isSigned*/ false`. Think about it, there are two explanations: "An alignment should be positive", therefore the sign bit is unset, so `zext` and `sext` is equivalent. Or a second one: you have `i2 0b10` - a valid alignment, now you `sext` it: `i2 0b110` - no longer valid alignment. Reviewers: craig.topper, jyknight, hfinkel, erichkeane, rjmccall Reviewed By: hfinkel, rjmccall Subscribers: hfinkel, llvm-commits Differential Revision: https://reviews.llvm.org/D54653 llvm-svn: 352089
This commit is contained in:
parent
1ec465dbfd
commit
a95a7105ef
|
@ -2279,10 +2279,11 @@ public:
|
||||||
Value **TheCheck = nullptr) {
|
Value **TheCheck = nullptr) {
|
||||||
assert(isa<PointerType>(PtrValue->getType()) &&
|
assert(isa<PointerType>(PtrValue->getType()) &&
|
||||||
"trying to create an alignment assumption on a non-pointer?");
|
"trying to create an alignment assumption on a non-pointer?");
|
||||||
|
assert(Alignment != 0 && "Invalid Alignment");
|
||||||
auto *PtrTy = cast<PointerType>(PtrValue->getType());
|
auto *PtrTy = cast<PointerType>(PtrValue->getType());
|
||||||
Type *IntPtrTy = getIntPtrTy(DL, PtrTy->getAddressSpace());
|
Type *IntPtrTy = getIntPtrTy(DL, PtrTy->getAddressSpace());
|
||||||
|
|
||||||
Value *Mask = ConstantInt::get(IntPtrTy, Alignment > 0 ? Alignment - 1 : 0);
|
Value *Mask = ConstantInt::get(IntPtrTy, Alignment - 1);
|
||||||
return CreateAlignmentAssumptionHelper(DL, PtrValue, Mask, IntPtrTy,
|
return CreateAlignmentAssumptionHelper(DL, PtrValue, Mask, IntPtrTy,
|
||||||
OffsetValue, TheCheck);
|
OffsetValue, TheCheck);
|
||||||
}
|
}
|
||||||
|
@ -2309,15 +2310,10 @@ public:
|
||||||
Type *IntPtrTy = getIntPtrTy(DL, PtrTy->getAddressSpace());
|
Type *IntPtrTy = getIntPtrTy(DL, PtrTy->getAddressSpace());
|
||||||
|
|
||||||
if (Alignment->getType() != IntPtrTy)
|
if (Alignment->getType() != IntPtrTy)
|
||||||
Alignment = CreateIntCast(Alignment, IntPtrTy, /*isSigned*/ true,
|
Alignment = CreateIntCast(Alignment, IntPtrTy, /*isSigned*/ false,
|
||||||
"alignmentcast");
|
"alignmentcast");
|
||||||
Value *IsPositive =
|
|
||||||
CreateICmp(CmpInst::ICMP_SGT, Alignment,
|
Value *Mask = CreateSub(Alignment, ConstantInt::get(IntPtrTy, 1), "mask");
|
||||||
ConstantInt::get(Alignment->getType(), 0), "ispositive");
|
|
||||||
Value *PositiveMask =
|
|
||||||
CreateSub(Alignment, ConstantInt::get(IntPtrTy, 1), "positivemask");
|
|
||||||
Value *Mask = CreateSelect(IsPositive, PositiveMask,
|
|
||||||
ConstantInt::get(IntPtrTy, 0), "mask");
|
|
||||||
|
|
||||||
return CreateAlignmentAssumptionHelper(DL, PtrValue, Mask, IntPtrTy,
|
return CreateAlignmentAssumptionHelper(DL, PtrValue, Mask, IntPtrTy,
|
||||||
OffsetValue, TheCheck);
|
OffsetValue, TheCheck);
|
||||||
|
|
Loading…
Reference in New Issue