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

Daniel Neilson via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 12 13:33:37 PST 2018


Author: dneilson
Date: Fri Jan 12 13:33:37 2018
New Revision: 322403

URL: http://llvm.org/viewvc/llvm-project?rev=322403&view=rev
Log:
[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.

Modified:
    llvm/trunk/include/llvm/IR/IntrinsicInst.h
    llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp
    llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
    llvm/trunk/lib/IR/Verifier.cpp
    llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
    llvm/trunk/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
    llvm/trunk/lib/Transforms/Scalar/AlignmentFromAssumptions.cpp
    llvm/trunk/lib/Transforms/Scalar/SROA.cpp
    llvm/trunk/test/Verifier/memcpy.ll

Modified: llvm/trunk/include/llvm/IR/IntrinsicInst.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/IntrinsicInst.h?rev=322403&r1=322402&r2=322403&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/IntrinsicInst.h (original)
+++ llvm/trunk/include/llvm/IR/IntrinsicInst.h Fri Jan 12 13:33:37 2018
@@ -414,7 +414,9 @@ namespace llvm {
       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); }
 

Modified: llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp?rev=322403&r1=322402&r2=322403&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp (original)
+++ llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp Fri Jan 12 13:33:37 2018
@@ -1610,7 +1610,7 @@ bool CodeGenPrepare::optimizeCallInst(Ca
       if (MemTransferInst *MTI = dyn_cast<MemTransferInst>(MI))
         Align = std::min(Align, getKnownAlignment(MTI->getSource(), *DL));
       if (Align > MI->getAlignment())
-        MI->setAlignment(ConstantInt::get(MI->getAlignmentType(), Align));
+        MI->setAlignment(Align);
     }
   }
 

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp?rev=322403&r1=322402&r2=322403&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp Fri Jan 12 13:33:37 2018
@@ -5008,13 +5008,14 @@ SelectionDAGBuilder::visitIntrinsicCall(
   case Intrinsic::longjmp:
     return &"_longjmp"[!TLI.usesUnderscoreLongJmp()];
   case Intrinsic::memcpy: {
+    const auto &MCI = cast<MemCpyInst>(I);
     SDValue Op1 = getValue(I.getArgOperand(0));
     SDValue Op2 = getValue(I.getArgOperand(1));
     SDValue Op3 = getValue(I.getArgOperand(2));
-    unsigned Align = cast<ConstantInt>(I.getArgOperand(3))->getZExtValue();
+    unsigned Align = MCI.getAlignment();
     if (!Align)
       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());
     SDValue MC = DAG.getMemcpy(getRoot(), sdl, Op1, Op2, Op3, Align, isVol,
                                false, isTC,
@@ -5024,13 +5025,14 @@ SelectionDAGBuilder::visitIntrinsicCall(
     return nullptr;
   }
   case Intrinsic::memset: {
+    const auto &MSI = cast<MemSetInst>(I);
     SDValue Op1 = getValue(I.getArgOperand(0));
     SDValue Op2 = getValue(I.getArgOperand(1));
     SDValue Op3 = getValue(I.getArgOperand(2));
-    unsigned Align = cast<ConstantInt>(I.getArgOperand(3))->getZExtValue();
+    unsigned Align = MSI.getAlignment();
     if (!Align)
       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());
     SDValue MS = DAG.getMemset(getRoot(), sdl, Op1, Op2, Op3, Align, isVol,
                                isTC, MachinePointerInfo(I.getArgOperand(0)));
@@ -5038,13 +5040,14 @@ SelectionDAGBuilder::visitIntrinsicCall(
     return nullptr;
   }
   case Intrinsic::memmove: {
+    const auto &MMI = cast<MemMoveInst>(I);
     SDValue Op1 = getValue(I.getArgOperand(0));
     SDValue Op2 = getValue(I.getArgOperand(1));
     SDValue Op3 = getValue(I.getArgOperand(2));
-    unsigned Align = cast<ConstantInt>(I.getArgOperand(3))->getZExtValue();
+    unsigned Align = MMI.getAlignment();
     if (!Align)
       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());
     SDValue MM = DAG.getMemmove(getRoot(), sdl, Op1, Op2, Op3, Align, isVol,
                                 isTC, MachinePointerInfo(I.getArgOperand(0)),

Modified: llvm/trunk/lib/IR/Verifier.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Verifier.cpp?rev=322403&r1=322402&r2=322403&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Verifier.cpp (original)
+++ llvm/trunk/lib/IR/Verifier.cpp Fri Jan 12 13:33:37 2018
@@ -4048,9 +4048,13 @@ void Verifier::visitIntrinsicCallSite(In
     Assert(AlignCI,
            "alignment argument of memory intrinsics must be a constant int",
            CS);
-    const APInt &AlignVal = AlignCI->getValue();
-    Assert(AlignCI->isZero() || AlignVal.isPowerOf2(),
-           "alignment argument of memory intrinsics must be a power of 2", CS);
+    const auto *MI = cast<MemIntrinsic>(CS.getInstruction());
+    auto IsValidAlignment = [&](unsigned Alignment) -> bool {
+      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)),
            "isvolatile argument of memory intrinsics must be a constant int",
            CS);

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp?rev=322403&r1=322402&r2=322403&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp Fri Jan 12 13:33:37 2018
@@ -190,7 +190,7 @@ Instruction *InstCombiner::SimplifyMemTr
   unsigned CopyAlign = MI->getAlignment();
 
   if (CopyAlign < MinAlign) {
-    MI->setAlignment(ConstantInt::get(MI->getAlignmentType(), MinAlign, false));
+    MI->setAlignment(MinAlign);
     return MI;
   }
 
@@ -265,8 +265,7 @@ Instruction *InstCombiner::SimplifyMemTr
 Instruction *InstCombiner::SimplifyMemSet(MemSetInst *MI) {
   unsigned Alignment = getKnownAlignment(MI->getDest(), DL, MI, &AC, &DT);
   if (MI->getAlignment() < Alignment) {
-    MI->setAlignment(ConstantInt::get(MI->getAlignmentType(),
-                                             Alignment, false));
+    MI->setAlignment(Alignment);
     return MI;
   }
 

Modified: llvm/trunk/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp?rev=322403&r1=322402&r2=322403&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp (original)
+++ llvm/trunk/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp Fri Jan 12 13:33:37 2018
@@ -1385,10 +1385,10 @@ void DFSanVisitor::visitMemTransferInst(
   Value *AlignShadow;
   if (ClPreserveAlignment) {
     AlignShadow = IRB.CreateMul(I.getAlignmentCst(),
-                                ConstantInt::get(I.getAlignmentCst()->getType(),
+                                ConstantInt::get(I.getAlignmentType(),
                                                  DFSF.DFS.ShadowWidth / 8));
   } else {
-    AlignShadow = ConstantInt::get(I.getAlignmentCst()->getType(),
+    AlignShadow = ConstantInt::get(I.getAlignmentType(),
                                    DFSF.DFS.ShadowWidth / 8);
   }
   Type *Int8Ptr = Type::getInt8PtrTy(*DFSF.DFS.Ctx);

Modified: llvm/trunk/lib/Transforms/Scalar/AlignmentFromAssumptions.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/AlignmentFromAssumptions.cpp?rev=322403&r1=322402&r2=322403&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/AlignmentFromAssumptions.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/AlignmentFromAssumptions.cpp Fri Jan 12 13:33:37 2018
@@ -374,8 +374,7 @@ bool AlignmentFromAssumptionsPass::proce
           NewAlignment = std::max(NewAlignment, AltSrcAlignment);
 
         if (NewAlignment > MI->getAlignment()) {
-          MI->setAlignment(ConstantInt::get(Type::getInt32Ty(
-            MI->getParent()->getContext()), NewAlignment));
+          MI->setAlignment(NewAlignment);
           ++NumMemIntAlignChanged;
         }
 
@@ -385,8 +384,7 @@ bool AlignmentFromAssumptionsPass::proce
         assert((!isa<MemIntrinsic>(MI) || isa<MemSetInst>(MI)) &&
                "Unknown memory intrinsic");
 
-        MI->setAlignment(ConstantInt::get(Type::getInt32Ty(
-          MI->getParent()->getContext()), NewDestAlignment));
+        MI->setAlignment(NewDestAlignment);
         ++NumMemIntAlignChanged;
       }
     }

Modified: llvm/trunk/lib/Transforms/Scalar/SROA.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SROA.cpp?rev=322403&r1=322402&r2=322403&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/SROA.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/SROA.cpp Fri Jan 12 13:33:37 2018
@@ -2684,8 +2684,7 @@ private:
       assert(!IsSplit);
       assert(NewBeginOffset == BeginOffset);
       II.setDest(getNewAllocaSlicePtr(IRB, OldPtr->getType()));
-      Type *CstTy = II.getAlignmentCst()->getType();
-      II.setAlignment(ConstantInt::get(CstTy, getSliceAlign()));
+      II.setAlignment(getSliceAlign());
 
       deleteIfTriviallyDead(OldPtr);
       return false;
@@ -2807,9 +2806,7 @@ private:
         II.setSource(AdjustedPtr);
 
       if (II.getAlignment() > SliceAlign) {
-        Type *CstTy = II.getAlignmentCst()->getType();
-        II.setAlignment(
-            ConstantInt::get(CstTy, MinAlign(II.getAlignment(), SliceAlign)));
+        II.setAlignment(MinAlign(II.getAlignment(), SliceAlign));
       }
 
       DEBUG(dbgs() << "          to: " << II << "\n");

Modified: llvm/trunk/test/Verifier/memcpy.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Verifier/memcpy.ll?rev=322403&r1=322402&r2=322403&view=diff
==============================================================================
--- llvm/trunk/test/Verifier/memcpy.ll (original)
+++ llvm/trunk/test/Verifier/memcpy.ll Fri Jan 12 13:33:37 2018
@@ -1,6 +1,6 @@
 ; 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) {
   call void @llvm.memcpy.p0i8.p0i8.i32(i8* %P, i8* %Q, i32 4, i32 3, i1 false)




More information about the llvm-commits mailing list