[NFC] Change MemIntrinsicInst::setAlignment() to take an unsigned instead of a Constant

Summary:
 In preparation for https://reviews.llvm.org/D41675 this NFC changes this
prototype of MemIntrinsicInst::setAlignment() to accept an unsigned instead
of a Constant.

llvm-svn: 322403
This commit is contained in:
Daniel Neilson 2018-01-12 21:33:37 +00:00
parent 44dfa1de3b
commit 2409d24201
9 changed files with 29 additions and 26 deletions

View File

@ -414,7 +414,9 @@ namespace llvm {
return !getVolatileCst()->isZero(); return !getVolatileCst()->isZero();
} }
void setAlignment(Constant *A) { setArgOperand(ARG_ALIGN, A); } void setAlignment(unsigned Align) {
setArgOperand(ARG_ALIGN, ConstantInt::get(getAlignmentType(), Align));
}
void setVolatile(Constant *V) { setArgOperand(ARG_VOLATILE, V); } void setVolatile(Constant *V) { setArgOperand(ARG_VOLATILE, V); }

View File

@ -1610,7 +1610,7 @@ bool CodeGenPrepare::optimizeCallInst(CallInst *CI, bool &ModifiedDT) {
if (MemTransferInst *MTI = dyn_cast<MemTransferInst>(MI)) if (MemTransferInst *MTI = dyn_cast<MemTransferInst>(MI))
Align = std::min(Align, getKnownAlignment(MTI->getSource(), *DL)); Align = std::min(Align, getKnownAlignment(MTI->getSource(), *DL));
if (Align > MI->getAlignment()) if (Align > MI->getAlignment())
MI->setAlignment(ConstantInt::get(MI->getAlignmentType(), Align)); MI->setAlignment(Align);
} }
} }

View File

@ -5008,13 +5008,14 @@ SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I, unsigned Intrinsic) {
case Intrinsic::longjmp: case Intrinsic::longjmp:
return &"_longjmp"[!TLI.usesUnderscoreLongJmp()]; return &"_longjmp"[!TLI.usesUnderscoreLongJmp()];
case Intrinsic::memcpy: { case Intrinsic::memcpy: {
const auto &MCI = cast<MemCpyInst>(I);
SDValue Op1 = getValue(I.getArgOperand(0)); SDValue Op1 = getValue(I.getArgOperand(0));
SDValue Op2 = getValue(I.getArgOperand(1)); SDValue Op2 = getValue(I.getArgOperand(1));
SDValue Op3 = getValue(I.getArgOperand(2)); SDValue Op3 = getValue(I.getArgOperand(2));
unsigned Align = cast<ConstantInt>(I.getArgOperand(3))->getZExtValue(); unsigned Align = MCI.getAlignment();
if (!Align) if (!Align)
Align = 1; // @llvm.memcpy defines 0 and 1 to both mean no alignment. Align = 1; // @llvm.memcpy defines 0 and 1 to both mean no alignment.
bool isVol = cast<ConstantInt>(I.getArgOperand(4))->getZExtValue(); bool isVol = MCI.isVolatile();
bool isTC = I.isTailCall() && isInTailCallPosition(&I, DAG.getTarget()); bool isTC = I.isTailCall() && isInTailCallPosition(&I, DAG.getTarget());
SDValue MC = DAG.getMemcpy(getRoot(), sdl, Op1, Op2, Op3, Align, isVol, SDValue MC = DAG.getMemcpy(getRoot(), sdl, Op1, Op2, Op3, Align, isVol,
false, isTC, false, isTC,
@ -5024,13 +5025,14 @@ SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I, unsigned Intrinsic) {
return nullptr; return nullptr;
} }
case Intrinsic::memset: { case Intrinsic::memset: {
const auto &MSI = cast<MemSetInst>(I);
SDValue Op1 = getValue(I.getArgOperand(0)); SDValue Op1 = getValue(I.getArgOperand(0));
SDValue Op2 = getValue(I.getArgOperand(1)); SDValue Op2 = getValue(I.getArgOperand(1));
SDValue Op3 = getValue(I.getArgOperand(2)); SDValue Op3 = getValue(I.getArgOperand(2));
unsigned Align = cast<ConstantInt>(I.getArgOperand(3))->getZExtValue(); unsigned Align = MSI.getAlignment();
if (!Align) if (!Align)
Align = 1; // @llvm.memset defines 0 and 1 to both mean no alignment. Align = 1; // @llvm.memset defines 0 and 1 to both mean no alignment.
bool isVol = cast<ConstantInt>(I.getArgOperand(4))->getZExtValue(); bool isVol = MSI.isVolatile();
bool isTC = I.isTailCall() && isInTailCallPosition(&I, DAG.getTarget()); bool isTC = I.isTailCall() && isInTailCallPosition(&I, DAG.getTarget());
SDValue MS = DAG.getMemset(getRoot(), sdl, Op1, Op2, Op3, Align, isVol, SDValue MS = DAG.getMemset(getRoot(), sdl, Op1, Op2, Op3, Align, isVol,
isTC, MachinePointerInfo(I.getArgOperand(0))); isTC, MachinePointerInfo(I.getArgOperand(0)));
@ -5038,13 +5040,14 @@ SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I, unsigned Intrinsic) {
return nullptr; return nullptr;
} }
case Intrinsic::memmove: { case Intrinsic::memmove: {
const auto &MMI = cast<MemMoveInst>(I);
SDValue Op1 = getValue(I.getArgOperand(0)); SDValue Op1 = getValue(I.getArgOperand(0));
SDValue Op2 = getValue(I.getArgOperand(1)); SDValue Op2 = getValue(I.getArgOperand(1));
SDValue Op3 = getValue(I.getArgOperand(2)); SDValue Op3 = getValue(I.getArgOperand(2));
unsigned Align = cast<ConstantInt>(I.getArgOperand(3))->getZExtValue(); unsigned Align = MMI.getAlignment();
if (!Align) if (!Align)
Align = 1; // @llvm.memmove defines 0 and 1 to both mean no alignment. Align = 1; // @llvm.memmove defines 0 and 1 to both mean no alignment.
bool isVol = cast<ConstantInt>(I.getArgOperand(4))->getZExtValue(); bool isVol = MMI.isVolatile();
bool isTC = I.isTailCall() && isInTailCallPosition(&I, DAG.getTarget()); bool isTC = I.isTailCall() && isInTailCallPosition(&I, DAG.getTarget());
SDValue MM = DAG.getMemmove(getRoot(), sdl, Op1, Op2, Op3, Align, isVol, SDValue MM = DAG.getMemmove(getRoot(), sdl, Op1, Op2, Op3, Align, isVol,
isTC, MachinePointerInfo(I.getArgOperand(0)), isTC, MachinePointerInfo(I.getArgOperand(0)),

View File

@ -4048,9 +4048,13 @@ void Verifier::visitIntrinsicCallSite(Intrinsic::ID ID, CallSite CS) {
Assert(AlignCI, Assert(AlignCI,
"alignment argument of memory intrinsics must be a constant int", "alignment argument of memory intrinsics must be a constant int",
CS); CS);
const APInt &AlignVal = AlignCI->getValue(); const auto *MI = cast<MemIntrinsic>(CS.getInstruction());
Assert(AlignCI->isZero() || AlignVal.isPowerOf2(), auto IsValidAlignment = [&](unsigned Alignment) -> bool {
"alignment argument of memory intrinsics must be a power of 2", CS); return Alignment == 0 || isPowerOf2_32(Alignment);
};
Assert(IsValidAlignment(MI->getAlignment()),
"alignment argument of memory intrinsics must be 0 or a power of 2",
CS);
Assert(isa<ConstantInt>(CS.getArgOperand(4)), Assert(isa<ConstantInt>(CS.getArgOperand(4)),
"isvolatile argument of memory intrinsics must be a constant int", "isvolatile argument of memory intrinsics must be a constant int",
CS); CS);

View File

@ -190,7 +190,7 @@ Instruction *InstCombiner::SimplifyMemTransfer(MemIntrinsic *MI) {
unsigned CopyAlign = MI->getAlignment(); unsigned CopyAlign = MI->getAlignment();
if (CopyAlign < MinAlign) { if (CopyAlign < MinAlign) {
MI->setAlignment(ConstantInt::get(MI->getAlignmentType(), MinAlign, false)); MI->setAlignment(MinAlign);
return MI; return MI;
} }
@ -265,8 +265,7 @@ Instruction *InstCombiner::SimplifyMemTransfer(MemIntrinsic *MI) {
Instruction *InstCombiner::SimplifyMemSet(MemSetInst *MI) { Instruction *InstCombiner::SimplifyMemSet(MemSetInst *MI) {
unsigned Alignment = getKnownAlignment(MI->getDest(), DL, MI, &AC, &DT); unsigned Alignment = getKnownAlignment(MI->getDest(), DL, MI, &AC, &DT);
if (MI->getAlignment() < Alignment) { if (MI->getAlignment() < Alignment) {
MI->setAlignment(ConstantInt::get(MI->getAlignmentType(), MI->setAlignment(Alignment);
Alignment, false));
return MI; return MI;
} }

View File

@ -1385,10 +1385,10 @@ void DFSanVisitor::visitMemTransferInst(MemTransferInst &I) {
Value *AlignShadow; Value *AlignShadow;
if (ClPreserveAlignment) { if (ClPreserveAlignment) {
AlignShadow = IRB.CreateMul(I.getAlignmentCst(), AlignShadow = IRB.CreateMul(I.getAlignmentCst(),
ConstantInt::get(I.getAlignmentCst()->getType(), ConstantInt::get(I.getAlignmentType(),
DFSF.DFS.ShadowWidth / 8)); DFSF.DFS.ShadowWidth / 8));
} else { } else {
AlignShadow = ConstantInt::get(I.getAlignmentCst()->getType(), AlignShadow = ConstantInt::get(I.getAlignmentType(),
DFSF.DFS.ShadowWidth / 8); DFSF.DFS.ShadowWidth / 8);
} }
Type *Int8Ptr = Type::getInt8PtrTy(*DFSF.DFS.Ctx); Type *Int8Ptr = Type::getInt8PtrTy(*DFSF.DFS.Ctx);

View File

@ -374,8 +374,7 @@ bool AlignmentFromAssumptionsPass::processAssumption(CallInst *ACall) {
NewAlignment = std::max(NewAlignment, AltSrcAlignment); NewAlignment = std::max(NewAlignment, AltSrcAlignment);
if (NewAlignment > MI->getAlignment()) { if (NewAlignment > MI->getAlignment()) {
MI->setAlignment(ConstantInt::get(Type::getInt32Ty( MI->setAlignment(NewAlignment);
MI->getParent()->getContext()), NewAlignment));
++NumMemIntAlignChanged; ++NumMemIntAlignChanged;
} }
@ -385,8 +384,7 @@ bool AlignmentFromAssumptionsPass::processAssumption(CallInst *ACall) {
assert((!isa<MemIntrinsic>(MI) || isa<MemSetInst>(MI)) && assert((!isa<MemIntrinsic>(MI) || isa<MemSetInst>(MI)) &&
"Unknown memory intrinsic"); "Unknown memory intrinsic");
MI->setAlignment(ConstantInt::get(Type::getInt32Ty( MI->setAlignment(NewDestAlignment);
MI->getParent()->getContext()), NewDestAlignment));
++NumMemIntAlignChanged; ++NumMemIntAlignChanged;
} }
} }

View File

@ -2684,8 +2684,7 @@ private:
assert(!IsSplit); assert(!IsSplit);
assert(NewBeginOffset == BeginOffset); assert(NewBeginOffset == BeginOffset);
II.setDest(getNewAllocaSlicePtr(IRB, OldPtr->getType())); II.setDest(getNewAllocaSlicePtr(IRB, OldPtr->getType()));
Type *CstTy = II.getAlignmentCst()->getType(); II.setAlignment(getSliceAlign());
II.setAlignment(ConstantInt::get(CstTy, getSliceAlign()));
deleteIfTriviallyDead(OldPtr); deleteIfTriviallyDead(OldPtr);
return false; return false;
@ -2807,9 +2806,7 @@ private:
II.setSource(AdjustedPtr); II.setSource(AdjustedPtr);
if (II.getAlignment() > SliceAlign) { if (II.getAlignment() > SliceAlign) {
Type *CstTy = II.getAlignmentCst()->getType(); II.setAlignment(MinAlign(II.getAlignment(), SliceAlign));
II.setAlignment(
ConstantInt::get(CstTy, MinAlign(II.getAlignment(), SliceAlign)));
} }
DEBUG(dbgs() << " to: " << II << "\n"); DEBUG(dbgs() << " to: " << II << "\n");

View File

@ -1,6 +1,6 @@
; RUN: not opt -verify < %s 2>&1 | FileCheck %s ; RUN: not opt -verify < %s 2>&1 | FileCheck %s
; CHECK: alignment argument of memory intrinsics must be a power of 2 ; CHECK: alignment argument of memory intrinsics must be 0 or a power of 2
define void @foo(i8* %P, i8* %Q) { define void @foo(i8* %P, i8* %Q) {
call void @llvm.memcpy.p0i8.p0i8.i32(i8* %P, i8* %Q, i32 4, i32 3, i1 false) call void @llvm.memcpy.p0i8.p0i8.i32(i8* %P, i8* %Q, i32 4, i32 3, i1 false)