[llvm-branch-commits] [llvm] [NFC] Pass `DataLayout` to `Constant::getNullValue` call sites (PR #183214)

Shilei Tian via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Feb 24 15:55:47 PST 2026


https://github.com/shiltian created https://github.com/llvm/llvm-project/pull/183214

None

>From 2f870e692b1809e0735fabea38ed7ca3cf0ae261 Mon Sep 17 00:00:00 2001
From: Shilei Tian <i at tianshilei.me>
Date: Fri, 20 Feb 2026 23:15:33 -0500
Subject: [PATCH] [NFC] Pass `DataLayout` to `Constant::getNullValue` call
 sites

---
 add_dl_to_getnullvalue.py                     |  80 +++++++++++
 llvm/lib/Analysis/ConstantFolding.cpp         |  16 +--
 llvm/lib/Analysis/InstructionSimplify.cpp     | 124 ++++++++---------
 llvm/lib/Analysis/LazyValueInfo.cpp           |  10 +-
 llvm/lib/Analysis/Local.cpp                   |   2 +-
 llvm/lib/Analysis/MemoryBuiltins.cpp          |   4 +-
 llvm/lib/Analysis/ValueTracking.cpp           |   2 +-
 llvm/lib/AsmParser/LLParser.cpp               |   6 +-
 llvm/lib/Bitcode/Reader/BitcodeReader.cpp     |   3 +-
 llvm/lib/CodeGen/AtomicExpandPass.cpp         |   2 +-
 llvm/lib/CodeGen/CodeGenPrepare.cpp           |  21 +--
 .../lib/CodeGen/ComplexDeinterleavingPass.cpp |   8 +-
 llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp  |   2 +-
 llvm/lib/CodeGen/IntrinsicLowering.cpp        |   3 +-
 llvm/lib/CodeGen/ShadowStackGCLowering.cpp    |   6 +-
 llvm/lib/ExecutionEngine/ExecutionEngine.cpp  |   2 +-
 .../ExecutionEngine/Orc/ReOptimizeLayer.cpp   |   7 +-
 .../Frontend/Offloading/OffloadWrapper.cpp    |  13 +-
 llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp     |  68 +++++----
 llvm/lib/IR/AutoUpgrade.cpp                   |  73 ++++++----
 llvm/lib/IR/ConstantFold.cpp                  |   8 +-
 .../Target/AArch64/AArch64ISelLowering.cpp    |   3 +-
 .../Target/AArch64/AArch64StackTagging.cpp    |  16 ++-
 .../AArch64/AArch64TargetTransformInfo.cpp    |   7 +-
 .../AMDGPU/AMDGPUInstCombineIntrinsic.cpp     |   5 +-
 .../AMDGPU/AMDGPULowerBufferFatPointers.cpp   |   7 +-
 .../lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp |  13 +-
 .../Target/DirectX/DXILIntrinsicExpansion.cpp |   3 +-
 llvm/lib/Target/DirectX/DXILOpLowering.cpp    |   2 +-
 .../Target/Hexagon/HexagonVectorCombine.cpp   |   8 +-
 .../Target/NVPTX/NVPTXCtorDtorLowering.cpp    |   4 +-
 llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp   |   3 +-
 llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp |   3 +-
 .../Target/SPIRV/SPIRVInstructionSelector.cpp |   7 +-
 .../Target/SPIRV/SPIRVPrepareFunctions.cpp    |   3 +-
 .../WebAssembly/WebAssemblyRegStackify.cpp    |  10 +-
 .../WebAssemblyTargetTransformInfo.cpp        |   4 +-
 .../AggressiveInstCombine.cpp                 |   2 +-
 llvm/lib/Transforms/Coroutines/CoroFrame.cpp  |   2 +-
 llvm/lib/Transforms/IPO/GlobalOpt.cpp         |   3 +-
 llvm/lib/Transforms/IPO/LowerTypeTests.cpp    |  12 +-
 llvm/lib/Transforms/IPO/OpenMPOpt.cpp         |   6 +-
 .../lib/Transforms/IPO/WholeProgramDevirt.cpp |   4 +-
 .../InstCombine/InstCombineAddSub.cpp         |   4 +-
 .../InstCombine/InstCombineAndOrXor.cpp       |  26 ++--
 .../InstCombine/InstCombineCalls.cpp          |  11 +-
 .../InstCombine/InstCombineCasts.cpp          |  13 +-
 .../InstCombine/InstCombineCompares.cpp       | 130 ++++++++++--------
 .../InstCombine/InstCombineSelect.cpp         |   2 +-
 .../InstCombineSimplifyDemanded.cpp           |   2 +-
 .../InstCombine/InstructionCombining.cpp      |  14 +-
 .../Instrumentation/AddressSanitizer.cpp      |  39 +++---
 .../Instrumentation/GCOVProfiling.cpp         |  12 +-
 .../Instrumentation/HWAddressSanitizer.cpp    |   5 +-
 .../Instrumentation/InstrProfiling.cpp        |  23 ++--
 .../Instrumentation/MemorySanitizer.cpp       | 108 +++++++++------
 .../Instrumentation/PGOCtxProfLowering.cpp    |  10 +-
 .../Instrumentation/SanitizerCoverage.cpp     |  12 +-
 .../Instrumentation/TypeSanitizer.cpp         |   2 +-
 .../Scalar/ConstraintElimination.cpp          |   2 +-
 .../Scalar/CorrelatedValuePropagation.cpp     |   3 +-
 llvm/lib/Transforms/Scalar/GVN.cpp            |   4 +-
 llvm/lib/Transforms/Scalar/InferAlignment.cpp |   4 +-
 llvm/lib/Transforms/Scalar/NewGVN.cpp         |   2 +-
 llvm/lib/Transforms/Scalar/Reassociate.cpp    |  13 +-
 llvm/lib/Transforms/Scalar/Reg2Mem.cpp        |   3 +-
 .../lib/Transforms/Utils/AMDGPUEmitPrintf.cpp |   6 +-
 llvm/lib/Transforms/Utils/CodeExtractor.cpp   |  20 ++-
 .../Transforms/Utils/FunctionImportUtils.cpp  |   3 +-
 .../lib/Transforms/Utils/LowerGlobalDtors.cpp |   5 +-
 .../Transforms/Utils/MemoryTaggingSupport.cpp |   7 +-
 llvm/lib/Transforms/Utils/ModuleUtils.cpp     |   2 +-
 .../Utils/PromoteMemoryToRegister.cpp         |   5 +-
 llvm/lib/Transforms/Utils/SCCPSolver.cpp      |   5 +-
 llvm/lib/Transforms/Utils/SanitizerStats.cpp  |   4 +-
 .../Utils/ScalarEvolutionExpander.cpp         |  14 +-
 llvm/lib/Transforms/Utils/SimplifyCFG.cpp     |   3 +-
 .../lib/Transforms/Utils/SimplifyLibCalls.cpp |  32 ++---
 .../Vectorize/LoopIdiomVectorize.cpp          |   2 +-
 .../Transforms/Vectorize/SLPVectorizer.cpp    |  27 ++--
 .../lib/Transforms/Vectorize/VPlanRecipes.cpp |   8 +-
 .../Transforms/Vectorize/VectorCombine.cpp    |   4 +-
 82 files changed, 708 insertions(+), 470 deletions(-)
 create mode 100644 add_dl_to_getnullvalue.py

diff --git a/add_dl_to_getnullvalue.py b/add_dl_to_getnullvalue.py
new file mode 100644
index 0000000000000..154b5442a35b3
--- /dev/null
+++ b/add_dl_to_getnullvalue.py
@@ -0,0 +1,80 @@
+#!/usr/bin/env python3
+"""Add DataLayout argument to single-arg Constant::getNullValue calls in a file."""
+import sys
+
+
+def process_file(filepath, dl_expr):
+    with open(filepath, "r") as f:
+        content = f.read()
+
+    result = []
+    i = 0
+    pattern = "Constant::getNullValue("
+    changes = 0
+
+    while i < len(content):
+        pos = content.find(pattern, i)
+        if pos == -1:
+            result.append(content[i:])
+            break
+
+        result.append(content[i:pos])
+
+        line_start = content.rfind("\n", 0, pos) + 1
+        line_prefix = content[line_start:pos]
+        if "//" in line_prefix:
+            result.append(pattern)
+            i = pos + len(pattern)
+            continue
+
+        paren_start = pos + len(pattern)
+        depth = 1
+        j = paren_start
+
+        while j < len(content) and depth > 0:
+            ch = content[j]
+            if ch == "(":
+                depth += 1
+            elif ch == ")":
+                depth -= 1
+            j += 1
+
+        if depth != 0:
+            result.append(pattern)
+            i = paren_start
+            continue
+
+        arg = content[paren_start : j - 1]
+
+        d = 0
+        has_top_level_comma = False
+        for ch in arg:
+            if ch == "(":
+                d += 1
+            elif ch == ")":
+                d -= 1
+            elif ch == "," and d == 0:
+                has_top_level_comma = True
+                break
+
+        if has_top_level_comma:
+            result.append(content[pos:j])
+        else:
+            result.append(pattern + arg + ", " + dl_expr + ")")
+            changes += 1
+
+        i = j
+
+    new_content = "".join(result)
+    if changes > 0:
+        with open(filepath, "w") as f:
+            f.write(new_content)
+
+    return changes
+
+
+if __name__ == "__main__":
+    filepath = sys.argv[1]
+    dl_expr = sys.argv[2]
+    n = process_file(filepath, dl_expr)
+    print(f"{filepath}: {n} changes")
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index a96c0f0b086ef..efc575d424ea0 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -221,7 +221,7 @@ Constant *FoldBitCast(Constant *C, Type *DestTy, const DataLayout &DL) {
   SmallVector<Constant*, 32> Result;
   if (NumDstElt < NumSrcElt) {
     // Handle: bitcast (<4 x i32> <i32 0, i32 1, i32 2, i32 3> to <2 x i64>)
-    Constant *Zero = Constant::getNullValue(DstEltTy);
+    Constant *Zero = Constant::getNullValue(DstEltTy, &DL);
     unsigned Ratio = NumSrcElt/NumDstElt;
     unsigned SrcBitSize = SrcEltTy->getPrimitiveSizeInBits();
     unsigned SrcElt = 0;
@@ -233,7 +233,7 @@ Constant *FoldBitCast(Constant *C, Type *DestTy, const DataLayout &DL) {
         Constant *Src = C->getAggregateElement(SrcElt++);
         if (isa_and_nonnull<UndefValue>(Src))
           Src = Constant::getNullValue(
-              cast<VectorType>(C->getType())->getElementType());
+              cast<VectorType>(C->getType())->getElementType(), &DL);
         else
           Src = dyn_cast_or_null<ConstantInt>(Src);
         if (!Src)  // Reject constantexpr elements.
@@ -586,13 +586,13 @@ Constant *FoldReinterpretLoadFromConst(Constant *C, Type *LoadTy,
     if (Constant *Res = FoldReinterpretLoadFromConst(C, MapTy, Offset, DL)) {
       if (Res->isNullValue() && !LoadTy->isX86_AMXTy())
         // Materializing a zero can be done trivially without a bitcast
-        return Constant::getNullValue(LoadTy);
+        return Constant::getNullValue(LoadTy, &DL);
       Type *CastTy = LoadTy->isPtrOrPtrVectorTy() ? DL.getIntPtrType(LoadTy) : LoadTy;
       Res = FoldBitCast(Res, CastTy, DL);
       if (LoadTy->isPtrOrPtrVectorTy()) {
         // For vector of pointer, we needed to first convert to a vector of integer, then do vector inttoptr
         if (Res->isNullValue() && !LoadTy->isX86_AMXTy())
-          return Constant::getNullValue(LoadTy);
+          return Constant::getNullValue(LoadTy, &DL);
         if (DL.isNonIntegralPointerType(LoadTy->getScalarType()))
           // Be careful not to replace a load of an addrspace value with an inttoptr here
           return nullptr;
@@ -783,7 +783,7 @@ Constant *llvm::ConstantFoldLoadFromUniformValue(Constant *C, Type *Ty,
   if (!DL.typeSizeEqualsStoreSize(C->getType()))
     return nullptr;
   if (C->isNullValue() && !Ty->isX86_AMXTy())
-    return Constant::getNullValue(Ty);
+    return Constant::getNullValue(Ty, &DL);
   if (C->isAllOnesValue() &&
       (Ty->isIntOrIntVectorTy() || Ty->isFPOrFPVectorTy()))
     return Constant::getAllOnesValue(Ty);
@@ -1219,7 +1219,7 @@ Constant *llvm::ConstantFoldCompareInstOperands(
         // proper extension or truncation.
         if (Constant *C = ConstantFoldIntegerCast(CE0->getOperand(0), IntPtrTy,
                                                   /*IsSigned*/ false, DL)) {
-          Constant *Null = Constant::getNullValue(C->getType());
+          Constant *Null = Constant::getNullValue(C->getType(), &DL);
           return ConstantFoldCompareInstOperands(Predicate, C, Null, DL, TLI);
         }
       }
@@ -1231,7 +1231,7 @@ Constant *llvm::ConstantFoldCompareInstOperands(
         Type *AddrTy = DL.getAddressType(CE0->getOperand(0)->getType());
         if (CE0->getType() == AddrTy) {
           Constant *C = CE0->getOperand(0);
-          Constant *Null = Constant::getNullValue(C->getType());
+          Constant *Null = Constant::getNullValue(C->getType(), &DL);
           return ConstantFoldCompareInstOperands(Predicate, C, Null, DL, TLI);
         }
       }
@@ -1591,7 +1591,7 @@ Constant *llvm::ConstantFoldCastOperand(unsigned Opcode, Constant *C,
       unsigned AS = SrcIsPtr ? C->getType()->getPointerAddressSpace()
                              : DestTy->getPointerAddressSpace();
       if (DL.isNullPointerAllZeroes(AS))
-        return Constant::getNullValue(DestTy);
+        return Constant::getNullValue(DestTy, &DL);
     }
   }
 
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 31440794adf80..6d356678881a9 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -610,7 +610,7 @@ static Value *simplifyAddInst(Value *Op0, Value *Op1, bool IsNSW, bool IsNUW,
 
   // If two operands are negative, return 0.
   if (isKnownNegation(Op0, Op1))
-    return Constant::getNullValue(Op0->getType());
+    return Constant::getNullValue(Op0->getType(), &Q.DL);
 
   // X + (Y - X) -> Y
   // (Y - X) + X -> Y
@@ -724,7 +724,7 @@ static Value *simplifyByDomEq(unsigned Opcode, Value *Op0, Value *Op1,
     case Instruction::Xor:
     case Instruction::URem:
     case Instruction::SRem:
-      return Constant::getNullValue(Ty);
+      return Constant::getNullValue(Ty, &Q.DL);
 
     case Instruction::SDiv:
     case Instruction::UDiv:
@@ -764,20 +764,20 @@ static Value *simplifySubInst(Value *Op0, Value *Op1, bool IsNSW, bool IsNUW,
 
   // X - X -> 0
   if (Op0 == Op1)
-    return Constant::getNullValue(Op0->getType());
+    return Constant::getNullValue(Op0->getType(), &Q.DL);
 
   // Is this a negation?
   if (match(Op0, m_Zero())) {
     // 0 - X -> 0 if the sub is NUW.
     if (IsNUW)
-      return Constant::getNullValue(Op0->getType());
+      return Constant::getNullValue(Op0->getType(), &Q.DL);
 
     KnownBits Known = computeKnownBits(Op1, Q);
     if (Known.Zero.isMaxSignedValue()) {
       // Op1 is either 0 or the minimum signed value. If the sub is NSW, then
       // Op1 must be 0 because negating the minimum signed value is undefined.
       if (IsNSW)
-        return Constant::getNullValue(Op0->getType());
+        return Constant::getNullValue(Op0->getType(), &Q.DL);
 
       // 0 - X -> X if X is 0 or the minimum signed value.
       return Op1;
@@ -908,7 +908,7 @@ static Value *simplifyMulInst(Value *Op0, Value *Op1, bool IsNSW, bool IsNUW,
   // X * undef -> 0
   // X * 0 -> 0
   if (Q.isUndefValue(Op1) || match(Op1, m_Zero()))
-    return Constant::getNullValue(Op0->getType());
+    return Constant::getNullValue(Op0->getType(), &Q.DL);
 
   // X * 1 -> X
   if (match(Op1, m_One()))
@@ -1070,17 +1070,17 @@ static Value *simplifyDivRem(Instruction::BinaryOps Opcode, Value *Op0,
   // undef / X -> 0
   // undef % X -> 0
   if (Q.isUndefValue(Op0))
-    return Constant::getNullValue(Ty);
+    return Constant::getNullValue(Ty, &Q.DL);
 
   // 0 / X -> 0
   // 0 % X -> 0
   if (match(Op0, m_Zero()))
-    return Constant::getNullValue(Op0->getType());
+    return Constant::getNullValue(Op0->getType(), &Q.DL);
 
   // X / X -> 1
   // X % X -> 0
   if (Op0 == Op1)
-    return IsDiv ? ConstantInt::get(Ty, 1) : Constant::getNullValue(Ty);
+    return IsDiv ? ConstantInt::get(Ty, 1) : Constant::getNullValue(Ty, &Q.DL);
 
   KnownBits Known = computeKnownBits(Op1, Q);
   // X / 0 -> poison
@@ -1097,7 +1097,7 @@ static Value *simplifyDivRem(Instruction::BinaryOps Opcode, Value *Op0,
   // or remainder-by-zero, so assume the divisor is 1.
   //   e.g. 1, zext (i8 X), sdiv X (Y and 1)
   if (Known.countMinLeadingZeros() == Known.getBitWidth() - 1)
-    return IsDiv ? Op0 : Constant::getNullValue(Ty);
+    return IsDiv ? Op0 : Constant::getNullValue(Ty, &Q.DL);
 
   // If X * Y does not overflow, then:
   //   X * Y / Y -> X
@@ -1111,12 +1111,12 @@ static Value *simplifyDivRem(Instruction::BinaryOps Opcode, Value *Op0,
         (!IsSigned && Q.IIQ.hasNoUnsignedWrap(Mul)) ||
         (IsSigned && match(X, m_SDiv(m_Value(), m_Specific(Op1)))) ||
         (!IsSigned && match(X, m_UDiv(m_Value(), m_Specific(Op1))))) {
-      return IsDiv ? X : Constant::getNullValue(Op0->getType());
+      return IsDiv ? X : Constant::getNullValue(Op0->getType(), &Q.DL);
     }
   }
 
   if (isDivZero(Op0, Op1, Q, MaxRecurse, IsSigned))
-    return IsDiv ? Constant::getNullValue(Op0->getType()) : Op0;
+    return IsDiv ? Constant::getNullValue(Op0->getType(), &Q.DL) : Op0;
 
   if (Value *V = simplifyByDomEq(Opcode, Op0, Op1, Q, MaxRecurse))
     return V;
@@ -1186,7 +1186,7 @@ static Value *simplifyRem(Instruction::BinaryOps Opcode, Value *Op0, Value *Op1,
          match(Op0, m_NSWShl(m_Specific(Op1), m_Value()))) ||
         (Opcode == Instruction::URem &&
          match(Op0, m_NUWShl(m_Specific(Op1), m_Value()))))
-      return Constant::getNullValue(Op0->getType());
+      return Constant::getNullValue(Op0->getType(), &Q.DL);
 
     const APInt *C0;
     if (match(Op1, m_APInt(C0))) {
@@ -1201,7 +1201,7 @@ static Value *simplifyRem(Instruction::BinaryOps Opcode, Value *Op0, Value *Op1,
                       m_NUWMul(m_Value(), m_CheckedInt([C0](const APInt &C) {
                                  return C.urem(*C0).isZero();
                                }))))
-        return Constant::getNullValue(Op0->getType());
+        return Constant::getNullValue(Op0->getType(), &Q.DL);
     }
   }
   return nullptr;
@@ -1311,7 +1311,7 @@ static Value *simplifyShift(Instruction::BinaryOps Opcode, Value *Op0,
 
   // 0 shift by X -> 0
   if (match(Op0, m_Zero()))
-    return Constant::getNullValue(Op0->getType());
+    return Constant::getNullValue(Op0->getType(), &Q.DL);
 
   // X shift by 0 -> X
   // Shift-by-sign-extended bool must be shift-by-0 because shift-by-all-ones
@@ -1378,12 +1378,12 @@ static Value *simplifyRightShift(Instruction::BinaryOps Opcode, Value *Op0,
 
   // X >> X -> 0
   if (Op0 == Op1)
-    return Constant::getNullValue(Op0->getType());
+    return Constant::getNullValue(Op0->getType(), &Q.DL);
 
   // undef >> X -> 0
   // undef >> X -> undef (if it's exact)
   if (Q.isUndefValue(Op0))
-    return IsExact ? Op0 : Constant::getNullValue(Op0->getType());
+    return IsExact ? Op0 : Constant::getNullValue(Op0->getType(), &Q.DL);
 
   // The low bit cannot be shifted out of an exact shift if it is set.
   // TODO: Generalize by counting trailing zeros (see fold for exact division).
@@ -1408,7 +1408,7 @@ static Value *simplifyShlInst(Value *Op0, Value *Op1, bool IsNSW, bool IsNUW,
   // undef << X -> 0
   // undef << X -> undef if (if it's NSW/NUW)
   if (Q.isUndefValue(Op0))
-    return IsNSW || IsNUW ? Op0 : Constant::getNullValue(Ty);
+    return IsNSW || IsNUW ? Op0 : Constant::getNullValue(Ty, &Q.DL);
 
   // (X >> A) << A -> X
   Value *X;
@@ -1427,7 +1427,7 @@ static Value *simplifyShlInst(Value *Op0, Value *Op1, bool IsNSW, bool IsNUW,
   // produce poison is 0, and "0 << (bitwidth-1) --> 0".
   if (IsNSW && IsNUW &&
       match(Op1, m_SpecificInt(Ty->getScalarSizeInBits() - 1)))
-    return Constant::getNullValue(Ty);
+    return Constant::getNullValue(Ty, &Q.DL);
 
   return nullptr;
 }
@@ -2022,7 +2022,7 @@ static Value *simplifyAndCommutative(Value *Op0, Value *Op1,
                                      unsigned MaxRecurse) {
   // ~A & A =  0
   if (match(Op0, m_Not(m_Specific(Op1))))
-    return Constant::getNullValue(Op0->getType());
+    return Constant::getNullValue(Op0->getType(), &Q.DL);
 
   // (A | ?) & A = A
   if (match(Op0, m_c_Or(m_Specific(Op1), m_Value())))
@@ -2049,7 +2049,7 @@ static Value *simplifyAndCommutative(Value *Op0, Value *Op1,
   // (A - 1) & A --> 0 (if A is a power-of-2 or 0)
   if (match(Op0, m_Add(m_Specific(Op1), m_AllOnes())) &&
       isKnownToBeAPowerOfTwo(Op1, Q.DL, /*OrZero*/ true, Q.AC, Q.CxtI, Q.DT))
-    return Constant::getNullValue(Op1->getType());
+    return Constant::getNullValue(Op1->getType(), &Q.DL);
 
   // (x << N) & ((x << M) - 1) --> 0, where x is known to be a power of 2 and
   // M <= N.
@@ -2058,7 +2058,7 @@ static Value *simplifyAndCommutative(Value *Op0, Value *Op1,
       match(Op1, m_Add(m_Shl(m_Specific(X), m_APInt(Shift2)), m_AllOnes())) &&
       isKnownToBeAPowerOfTwo(X, Q.DL, /*OrZero*/ true, Q.AC, Q.CxtI) &&
       Shift1->uge(*Shift2))
-    return Constant::getNullValue(Op0->getType());
+    return Constant::getNullValue(Op0->getType(), &Q.DL);
 
   if (Value *V =
           simplifyAndOrWithICmpEq(Instruction::And, Op0, Op1, Q, MaxRecurse))
@@ -2080,7 +2080,7 @@ static Value *simplifyAndInst(Value *Op0, Value *Op1, const SimplifyQuery &Q,
 
   // X & undef -> 0
   if (Q.isUndefValue(Op1))
-    return Constant::getNullValue(Op0->getType());
+    return Constant::getNullValue(Op0->getType(), &Q.DL);
 
   // X & X = X
   if (Op0 == Op1)
@@ -2088,7 +2088,7 @@ static Value *simplifyAndInst(Value *Op0, Value *Op1, const SimplifyQuery &Q,
 
   // X & 0 = 0
   if (match(Op1, m_Zero()))
-    return Constant::getNullValue(Op0->getType());
+    return Constant::getNullValue(Op0->getType(), &Q.DL);
 
   // X & -1 = X
   if (match(Op1, m_AllOnes()))
@@ -2214,14 +2214,14 @@ static Value *simplifyAndInst(Value *Op0, Value *Op1, const SimplifyQuery &Q,
                          m_CombineAnd(m_BinOp(Or),
                                       m_c_Or(m_Deferred(X), m_Value(Y))))) &&
       match(Op1, m_c_Xor(m_Specific(Or), m_Specific(Y))))
-    return Constant::getNullValue(Op0->getType());
+    return Constant::getNullValue(Op0->getType(), &Q.DL);
 
   const APInt *C1;
   Value *A;
   // (A ^ C) & (A ^ ~C) -> 0
   if (match(Op0, m_Xor(m_Value(A), m_APInt(C1))) &&
       match(Op1, m_Xor(m_Specific(A), m_SpecificInt(~*C1))))
-    return Constant::getNullValue(Op0->getType());
+    return Constant::getNullValue(Op0->getType(), &Q.DL);
 
   if (Op0->getType()->isIntOrIntVectorTy(1)) {
     if (std::optional<bool> Implied = isImpliedCondition(Op0, Op1, Q.DL)) {
@@ -2547,7 +2547,7 @@ static Value *simplifyXorInst(Value *Op0, Value *Op1, const SimplifyQuery &Q,
 
   // A ^ A = 0
   if (Op0 == Op1)
-    return Constant::getNullValue(Op0->getType());
+    return Constant::getNullValue(Op0->getType(), &Q.DL);
 
   // A ^ ~A  =  ~A ^ A  =  -1
   if (match(Op0, m_Not(m_Specific(Op1))) || match(Op1, m_Not(m_Specific(Op0))))
@@ -3385,16 +3385,16 @@ static Value *simplifyICmpWithBinOp(CmpPredicate Pred, Value *LHS, Value *RHS,
 
     // icmp (X+Y), X -> icmp Y, 0 for equalities or if there is no overflow.
     if ((A == RHS || B == RHS) && NoLHSWrapProblem)
-      if (Value *V = simplifyICmpInst(Pred, A == RHS ? B : A,
-                                      Constant::getNullValue(RHS->getType()), Q,
-                                      MaxRecurse - 1))
+      if (Value *V = simplifyICmpInst(
+              Pred, A == RHS ? B : A,
+              Constant::getNullValue(RHS->getType(), &Q.DL), Q, MaxRecurse - 1))
         return V;
 
     // icmp X, (X+Y) -> icmp 0, Y for equalities or if there is no overflow.
     if ((C == LHS || D == LHS) && NoRHSWrapProblem)
-      if (Value *V =
-              simplifyICmpInst(Pred, Constant::getNullValue(LHS->getType()),
-                               C == LHS ? D : C, Q, MaxRecurse - 1))
+      if (Value *V = simplifyICmpInst(
+              Pred, Constant::getNullValue(LHS->getType(), &Q.DL),
+              C == LHS ? D : C, Q, MaxRecurse - 1))
         return V;
 
     // icmp (X+Y), (X+Z) -> icmp Y,Z for equalities or if there is no overflow.
@@ -3980,7 +3980,7 @@ static Value *simplifyICmpInst(CmpPredicate Pred, Value *LHS, Value *RHS,
           case ICmpInst::ICMP_EQ:
           case ICmpInst::ICMP_UGT:
           case ICmpInst::ICMP_UGE:
-            return Constant::getNullValue(ITy);
+            return Constant::getNullValue(ITy, &Q.DL);
 
           case ICmpInst::ICMP_NE:
           case ICmpInst::ICMP_ULT:
@@ -3992,13 +3992,13 @@ static Value *simplifyICmpInst(CmpPredicate Pred, Value *LHS, Value *RHS,
           case ICmpInst::ICMP_SGT:
           case ICmpInst::ICMP_SGE:
             return ConstantFoldCompareInstOperands(
-                ICmpInst::ICMP_SLT, C, Constant::getNullValue(C->getType()),
-                Q.DL);
+                ICmpInst::ICMP_SLT, C,
+                Constant::getNullValue(C->getType(), &Q.DL), Q.DL);
           case ICmpInst::ICMP_SLT:
           case ICmpInst::ICMP_SLE:
             return ConstantFoldCompareInstOperands(
-                ICmpInst::ICMP_SGE, C, Constant::getNullValue(C->getType()),
-                Q.DL);
+                ICmpInst::ICMP_SGE, C,
+                Constant::getNullValue(C->getType(), &Q.DL), Q.DL);
           }
         }
       }
@@ -4054,7 +4054,7 @@ static Value *simplifyICmpInst(CmpPredicate Pred, Value *LHS, Value *RHS,
           default:
             llvm_unreachable("Unknown ICmp predicate!");
           case ICmpInst::ICMP_EQ:
-            return Constant::getNullValue(ITy);
+            return Constant::getNullValue(ITy, &Q.DL);
           case ICmpInst::ICMP_NE:
             return Constant::getAllOnesValue(ITy);
 
@@ -4063,13 +4063,13 @@ static Value *simplifyICmpInst(CmpPredicate Pred, Value *LHS, Value *RHS,
           case ICmpInst::ICMP_SGT:
           case ICmpInst::ICMP_SGE:
             return ConstantFoldCompareInstOperands(
-                ICmpInst::ICMP_SLT, C, Constant::getNullValue(C->getType()),
-                Q.DL);
+                ICmpInst::ICMP_SLT, C,
+                Constant::getNullValue(C->getType(), &Q.DL), Q.DL);
           case ICmpInst::ICMP_SLT:
           case ICmpInst::ICMP_SLE:
             return ConstantFoldCompareInstOperands(
-                ICmpInst::ICMP_SGE, C, Constant::getNullValue(C->getType()),
-                Q.DL);
+                ICmpInst::ICMP_SGE, C,
+                Constant::getNullValue(C->getType(), &Q.DL), Q.DL);
 
           // If LHS is non-negative then LHS <u RHS.  If LHS is negative then
           // LHS >u RHS.
@@ -4077,18 +4077,18 @@ static Value *simplifyICmpInst(CmpPredicate Pred, Value *LHS, Value *RHS,
           case ICmpInst::ICMP_UGE:
             // Comparison is true iff the LHS <s 0.
             if (MaxRecurse)
-              if (Value *V = simplifyICmpInst(ICmpInst::ICMP_SLT, SrcOp,
-                                              Constant::getNullValue(SrcTy), Q,
-                                              MaxRecurse - 1))
+              if (Value *V = simplifyICmpInst(
+                      ICmpInst::ICMP_SLT, SrcOp,
+                      Constant::getNullValue(SrcTy, &Q.DL), Q, MaxRecurse - 1))
                 return V;
             break;
           case ICmpInst::ICMP_ULT:
           case ICmpInst::ICMP_ULE:
             // Comparison is true iff the LHS >=s 0.
             if (MaxRecurse)
-              if (Value *V = simplifyICmpInst(ICmpInst::ICMP_SGE, SrcOp,
-                                              Constant::getNullValue(SrcTy), Q,
-                                              MaxRecurse - 1))
+              if (Value *V = simplifyICmpInst(
+                      ICmpInst::ICMP_SGE, SrcOp,
+                      Constant::getNullValue(SrcTy, &Q.DL), Q, MaxRecurse - 1))
                 return V;
             break;
           }
@@ -4499,7 +4499,7 @@ static Value *simplifyWithOpsReplaced(Value *V,
       if ((Opcode == Instruction::Sub || Opcode == Instruction::Xor) &&
           NewOps[0] == NewOps[1] &&
           any_of(Ops, [=](const auto &Rep) { return NewOps[0] == Rep.second; }))
-        return Constant::getNullValue(I->getType());
+        return Constant::getNullValue(I->getType(), &Q.DL);
 
       // If we are substituting an absorber constant into a binop and extra
       // poison can't leak if we remove the select -- because both operands of
@@ -6027,7 +6027,7 @@ simplifyFSubInst(Value *Op0, Value *Op1, FastMathFlags FMF,
   if (FMF.noNaNs()) {
     // fsub nnan x, x ==> 0.0
     if (Op0 == Op1)
-      return Constant::getNullValue(Op0->getType());
+      return Constant::getNullValue(Op0->getType(), &Q.DL);
 
     // With nnan: {+/-}Inf - X --> {+/-}Inf
     if (match(Op0, m_Inf()))
@@ -6882,14 +6882,14 @@ Value *llvm::simplifyBinaryIntrinsic(Intrinsic::ID IID, Type *ReturnType,
     if (match(Op0, m_LShr(m_Negative(), m_Value(X))))
       return X;
     if (match(Op0, m_AShr(m_Negative(), m_Value())))
-      return Constant::getNullValue(ReturnType);
+      return Constant::getNullValue(ReturnType, &Q.DL);
     break;
   }
   case Intrinsic::ptrmask: {
     // NOTE: We can't apply this simplifications based on the value of Op1
     // because we need to preserve provenance.
     if (Q.isUndefValue(Op0) || match(Op0, m_Zero()))
-      return Constant::getNullValue(Op0->getType());
+      return Constant::getNullValue(Op0->getType(), &Q.DL);
 
     assert(Op1->getType()->getScalarSizeInBits() ==
                Q.DL.getIndexTypeSizeInBits(Op0->getType()) &&
@@ -6985,7 +6985,7 @@ Value *llvm::simplifyBinaryIntrinsic(Intrinsic::ID IID, Type *ReturnType,
     // Fold to a constant if the relationship between operands can be
     // established with certainty
     if (isICmpTrue(CmpInst::ICMP_EQ, Op0, Op1, Q, RecursionLimit))
-      return Constant::getNullValue(ReturnType);
+      return Constant::getNullValue(ReturnType, &Q.DL);
 
     ICmpInst::Predicate PredGT =
         IID == Intrinsic::scmp ? ICmpInst::ICMP_SGT : ICmpInst::ICMP_UGT;
@@ -7005,7 +7005,7 @@ Value *llvm::simplifyBinaryIntrinsic(Intrinsic::ID IID, Type *ReturnType,
     // X - undef -> { 0, false }
     // undef - X -> { 0, false }
     if (Op0 == Op1 || Q.isUndefValue(Op0) || Q.isUndefValue(Op1))
-      return Constant::getNullValue(ReturnType);
+      return Constant::getNullValue(ReturnType, &Q.DL);
     break;
   case Intrinsic::uadd_with_overflow:
   case Intrinsic::sadd_with_overflow:
@@ -7015,7 +7015,7 @@ Value *llvm::simplifyBinaryIntrinsic(Intrinsic::ID IID, Type *ReturnType,
       return ConstantStruct::get(
           cast<StructType>(ReturnType),
           {Constant::getAllOnesValue(ReturnType->getStructElementType(0)),
-           Constant::getNullValue(ReturnType->getStructElementType(1))});
+           Constant::getNullValue(ReturnType->getStructElementType(1), &Q.DL)});
     }
     break;
   case Intrinsic::umul_with_overflow:
@@ -7023,11 +7023,11 @@ Value *llvm::simplifyBinaryIntrinsic(Intrinsic::ID IID, Type *ReturnType,
     // 0 * X -> { 0, false }
     // X * 0 -> { 0, false }
     if (match(Op0, m_Zero()) || match(Op1, m_Zero()))
-      return Constant::getNullValue(ReturnType);
+      return Constant::getNullValue(ReturnType, &Q.DL);
     // undef * X -> { 0, false }
     // X * undef -> { 0, false }
     if (Q.isUndefValue(Op0) || Q.isUndefValue(Op1))
-      return Constant::getNullValue(ReturnType);
+      return Constant::getNullValue(ReturnType, &Q.DL);
     break;
   case Intrinsic::uadd_sat:
     // sat(MAX + X) -> MAX
@@ -7053,12 +7053,12 @@ Value *llvm::simplifyBinaryIntrinsic(Intrinsic::ID IID, Type *ReturnType,
   case Intrinsic::usub_sat:
     // sat(0 - X) -> 0, sat(X - MAX) -> 0
     if (match(Op0, m_Zero()) || match(Op1, m_AllOnes()))
-      return Constant::getNullValue(ReturnType);
+      return Constant::getNullValue(ReturnType, &Q.DL);
     [[fallthrough]];
   case Intrinsic::ssub_sat:
     // X - X -> 0, X - undef -> 0, undef - X -> 0
     if (Op0 == Op1 || Q.isUndefValue(Op0) || Q.isUndefValue(Op1))
-      return Constant::getNullValue(ReturnType);
+      return Constant::getNullValue(ReturnType, &Q.DL);
     // X - 0 -> X
     if (match(Op1, m_Zero()))
       return Op0;
@@ -7318,11 +7318,11 @@ static Value *simplifyIntrinsic(CallBase *Call, Value *Callee,
 
     // X * 0 -> 0
     if (match(Op1, m_Zero()))
-      return Constant::getNullValue(ReturnType);
+      return Constant::getNullValue(ReturnType, &Q.DL);
 
     // X * undef -> 0
     if (Q.isUndefValue(Op1))
-      return Constant::getNullValue(ReturnType);
+      return Constant::getNullValue(ReturnType, &Q.DL);
 
     // X * (1 << Scale) -> X
     APInt ScaledOne =
diff --git a/llvm/lib/Analysis/LazyValueInfo.cpp b/llvm/lib/Analysis/LazyValueInfo.cpp
index b4d64536a5aca..b3645371cb0bc 100644
--- a/llvm/lib/Analysis/LazyValueInfo.cpp
+++ b/llvm/lib/Analysis/LazyValueInfo.cpp
@@ -847,14 +847,14 @@ void LazyValueInfoImpl::intersectAssumeOrGuardBlockValueConstantRange(
         switch (RK.AttrKind) {
         case Attribute::NonNull:
           BBLV = BBLV.intersect(ValueLatticeElement::getNot(
-              Constant::getNullValue(RK.WasOn->getType())));
+              Constant::getNullValue(RK.WasOn->getType(), &DL)));
           break;
 
         case Attribute::Dereferenceable:
           if (auto *CI = dyn_cast<ConstantInt>(RK.IRArgValue);
               CI && !CI->isZero())
             BBLV = BBLV.intersect(ValueLatticeElement::getNot(
-                Constant::getNullValue(RK.WasOn->getType())));
+                Constant::getNullValue(RK.WasOn->getType(), &DL)));
           break;
 
         default:
@@ -1449,7 +1449,7 @@ std::optional<ValueLatticeElement> LazyValueInfoImpl::getValueFromICmpCondition(
     match(X, m_PtrToIntSameSize(DL, m_Value(X)));
     match(Y, m_PtrToIntSameSize(DL, m_Value(Y)));
     if ((X == LHS && Y == RHS) || (X == RHS && Y == LHS)) {
-      Constant *NullVal = Constant::getNullValue(Val->getType());
+      Constant *NullVal = Constant::getNullValue(Val->getType(), &DL);
       if (EdgePred == ICmpInst::ICMP_EQ)
         return ValueLatticeElement::get(NullVal);
       return ValueLatticeElement::getNot(NullVal);
@@ -1472,11 +1472,11 @@ ValueLatticeElement LazyValueInfoImpl::getValueFromTrunc(Value *Val,
   if (Trunc->hasNoUnsignedWrap()) {
     if (IsTrueDest)
       return ValueLatticeElement::get(ConstantInt::get(Ty, 1));
-    return ValueLatticeElement::get(Constant::getNullValue(Ty));
+    return ValueLatticeElement::get(Constant::getNullValue(Ty, &DL));
   }
 
   if (IsTrueDest)
-    return ValueLatticeElement::getNot(Constant::getNullValue(Ty));
+    return ValueLatticeElement::getNot(Constant::getNullValue(Ty, &DL));
   return ValueLatticeElement::getNot(Constant::getAllOnesValue(Ty));
 }
 
diff --git a/llvm/lib/Analysis/Local.cpp b/llvm/lib/Analysis/Local.cpp
index c08ed4b739d43..9dcd4976469ab 100644
--- a/llvm/lib/Analysis/Local.cpp
+++ b/llvm/lib/Analysis/Local.cpp
@@ -75,5 +75,5 @@ Value *llvm::emitGEPOffset(IRBuilderBase *Builder, const DataLayout &DL,
     }
     AddOffset(Op);
   }
-  return Result ? Result : Constant::getNullValue(IntIdxTy);
+  return Result ? Result : Constant::getNullValue(IntIdxTy, &DL);
 }
diff --git a/llvm/lib/Analysis/MemoryBuiltins.cpp b/llvm/lib/Analysis/MemoryBuiltins.cpp
index c7f89de9f8b11..94833ffbbad52 100644
--- a/llvm/lib/Analysis/MemoryBuiltins.cpp
+++ b/llvm/lib/Analysis/MemoryBuiltins.cpp
@@ -443,7 +443,7 @@ Constant *llvm::getInitialValueOfAllocation(const Value *V,
   if ((AK & AllocFnKind::Uninitialized) != AllocFnKind::Unknown)
     return UndefValue::get(Ty);
   if ((AK & AllocFnKind::Zeroed) != AllocFnKind::Unknown)
-    return Constant::getNullValue(Ty);
+    return Constant::getNullValue(Ty, &Alloc->getDataLayout());
 
   return nullptr;
 }
@@ -718,7 +718,7 @@ Value *llvm::lowerObjectSizeCall(
     return nullptr;
 
   return MaxVal ? Constant::getAllOnesValue(ResultType)
-                : Constant::getNullValue(ResultType);
+                : Constant::getNullValue(ResultType, &DL);
 }
 
 STATISTIC(ObjectVisitorArgument,
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 5e280eee075aa..4ac9daa908bd0 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -6283,7 +6283,7 @@ Value *llvm::isBytewiseValue(Value *V, const DataLayout &DL) {
 
   // Handle 'null' ConstantArrayZero etc.
   if (C->isNullValue())
-    return Constant::getNullValue(Type::getInt8Ty(Ctx));
+    return Constant::getNullValue(Type::getInt8Ty(Ctx), &DL);
 
   // Constant floating-point values can be handled as integer values if the
   // corresponding integer value is "byteable".  An important case is 0.0.
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index a0a88eeb5d5c7..fa9019d5851b7 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -6769,12 +6769,12 @@ bool LLParser::convertValIDToValue(Type *Ty, ValID &ID, Value *&V,
     if (auto *TETy = dyn_cast<TargetExtType>(Ty))
       if (!TETy->hasProperty(TargetExtType::HasZeroInit))
         return error(ID.Loc, "invalid type for null constant");
-    V = Constant::getNullValue(Ty);
+    V = Constant::getNullValue(Ty, &M->getDataLayout());
     return false;
   case ValID::t_None:
     if (!Ty->isTokenTy())
       return error(ID.Loc, "invalid type for none constant");
-    V = Constant::getNullValue(Ty);
+    V = Constant::getNullValue(Ty, &M->getDataLayout());
     return false;
   case ValID::t_Poison:
     // FIXME: LabelTy should not be a first-class type.
@@ -6851,7 +6851,7 @@ bool LLParser::parseConstantValue(Type *Ty, Constant *&C) {
     return false;
   }
   case ValID::t_Null:
-    C = Constant::getNullValue(Ty);
+    C = Constant::getNullValue(Ty, &M->getDataLayout());
     return false;
   default:
     return error(Loc, "expected a constant value");
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 40f10dd7ca5d7..9ec249661212d 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -3319,7 +3319,8 @@ Error BitcodeReader::parseConstants() {
       if (auto *TETy = dyn_cast<TargetExtType>(CurTy))
         if (!TETy->hasProperty(TargetExtType::HasZeroInit))
           return error("Invalid type for a constant null value");
-      V = Constant::getNullValue(CurTy);
+      V = Constant::getNullValue(CurTy, TheModule ? &TheModule->getDataLayout()
+                                                  : nullptr);
       break;
     case bitc::CST_CODE_INTEGER:   // INTEGER: [intval]
       if (!CurTy->isIntOrIntVectorTy() || Record.empty())
diff --git a/llvm/lib/CodeGen/AtomicExpandPass.cpp b/llvm/lib/CodeGen/AtomicExpandPass.cpp
index 341a4618dbb47..5e7570edfe178 100644
--- a/llvm/lib/CodeGen/AtomicExpandPass.cpp
+++ b/llvm/lib/CodeGen/AtomicExpandPass.cpp
@@ -604,7 +604,7 @@ bool AtomicExpandImpl::expandAtomicLoadToCmpXchg(LoadInst *LI) {
 
   Value *Addr = LI->getPointerOperand();
   Type *Ty = LI->getType();
-  Constant *DummyVal = Constant::getNullValue(Ty);
+  Constant *DummyVal = Constant::getNullValue(Ty, DL);
 
   Value *Pair = Builder.CreateAtomicCmpXchg(
       Addr, DummyVal, DummyVal, LI->getAlign(), Order,
diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp
index c471b445d8d21..3cb46872bf87f 100644
--- a/llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -2211,7 +2211,7 @@ static bool foldURemOfLoopIncrement(Instruction *Rem, const DataLayout *DL,
   Value *RemAdd = Builder.CreateNUWAdd(NewRem, ConstantInt::get(Ty, 1));
   Value *RemCmp = Builder.CreateICmp(ICmpInst::ICMP_EQ, RemAdd, RemAmt);
   Value *RemSel =
-      Builder.CreateSelect(RemCmp, Constant::getNullValue(Ty), RemAdd);
+      Builder.CreateSelect(RemCmp, Constant::getNullValue(Ty, DL), RemAdd);
 
   NewRem->addIncoming(Start, L->getLoopPreheader());
   NewRem->addIncoming(RemSel, L->getLoopLatch());
@@ -2608,7 +2608,7 @@ static bool despeculateCountZeros(IntrinsicInst *CountZeros, LoopInfo &LI,
 
   // Replace the unconditional branch that was created by the first split with
   // a compare against zero and a conditional branch.
-  Value *Zero = Constant::getNullValue(Ty);
+  Value *Zero = Constant::getNullValue(Ty, DL);
   // Avoid introducing branch on poison. This also replaces the ctz operand.
   if (!isGuaranteedNotToBeUndefOrPoison(Op))
     Op = Builder.CreateFreeze(Op, Op->getName() + ".fr");
@@ -4262,7 +4262,7 @@ class AddressingModeCombiner {
     }
     assert(CommonType && "At least one non-null value must be!");
     for (auto *V : NullValue)
-      Map[V] = Constant::getNullValue(CommonType);
+      Map[V] = Constant::getNullValue(CommonType, &DL);
     return true;
   }
 
@@ -6046,7 +6046,7 @@ bool CodeGenPrepare::optimizeMemoryInst(Instruction *MemoryInst, Value *Addr,
 
     if (!ResultPtr && !AddrMode.BaseReg && !AddrMode.Scale &&
         !AddrMode.BaseOffs) {
-      SunkAddr = Constant::getNullValue(Addr->getType());
+      SunkAddr = Constant::getNullValue(Addr->getType(), DL);
     } else if (!ResultPtr) {
       return Modified;
     } else {
@@ -6223,7 +6223,7 @@ bool CodeGenPrepare::optimizeMemoryInst(Instruction *MemoryInst, Value *Addr,
     }
 
     if (!Result)
-      SunkAddr = Constant::getNullValue(Addr->getType());
+      SunkAddr = Constant::getNullValue(Addr->getType(), DL);
     else
       SunkAddr = Builder.CreateIntToPtr(Result, Addr->getType(), "sunkaddr");
   }
@@ -6337,8 +6337,8 @@ bool CodeGenPrepare::optimizeGatherScatterInst(Instruction *MemoryInst,
       auto *IndexTy = VectorType::get(ScalarIndexTy, NumElts);
       auto *SecondTy = GetElementPtrInst::getIndexedType(
           SourceTy, ArrayRef(Ops).drop_front());
-      NewAddr =
-          Builder.CreateGEP(SecondTy, NewAddr, Constant::getNullValue(IndexTy));
+      NewAddr = Builder.CreateGEP(SecondTy, NewAddr,
+                                  Constant::getNullValue(IndexTy, DL));
     } else {
       Value *Base = Ops[0];
       Value *Index = Ops[FinalIndex];
@@ -6346,8 +6346,8 @@ bool CodeGenPrepare::optimizeGatherScatterInst(Instruction *MemoryInst,
       // Create a scalar GEP if there are more than 2 operands.
       if (Ops.size() != 2) {
         // Replace the last index with 0.
-        Ops[FinalIndex] =
-            Constant::getNullValue(Ops[FinalIndex]->getType()->getScalarType());
+        Ops[FinalIndex] = Constant::getNullValue(
+            Ops[FinalIndex]->getType()->getScalarType(), DL);
         Base = Builder.CreateGEP(SourceTy, Base, ArrayRef(Ops).drop_front());
         SourceTy = GetElementPtrInst::getIndexedType(
             SourceTy, ArrayRef(Ops).drop_front());
@@ -6379,7 +6379,8 @@ bool CodeGenPrepare::optimizeGatherScatterInst(Instruction *MemoryInst,
              Intrinsic::masked_scatter);
       ScalarTy = MemoryInst->getOperand(0)->getType()->getScalarType();
     }
-    NewAddr = Builder.CreateGEP(ScalarTy, V, Constant::getNullValue(IndexTy));
+    NewAddr =
+        Builder.CreateGEP(ScalarTy, V, Constant::getNullValue(IndexTy, DL));
   } else {
     // Constant, SelectionDAGBuilder knows to check if its a splat.
     return false;
diff --git a/llvm/lib/CodeGen/ComplexDeinterleavingPass.cpp b/llvm/lib/CodeGen/ComplexDeinterleavingPass.cpp
index d6d2917e83a4d..79cd2bbd888a8 100644
--- a/llvm/lib/CodeGen/ComplexDeinterleavingPass.cpp
+++ b/llvm/lib/CodeGen/ComplexDeinterleavingPass.cpp
@@ -2432,12 +2432,14 @@ void ComplexDeinterleavingGraph::processReductionSingle(
   Value *NewInit = nullptr;
   if (auto *C = dyn_cast<Constant>(Init)) {
     if (C->isNullValue())
-      NewInit = Constant::getNullValue(NewVTy);
+      NewInit = Constant::getNullValue(NewVTy,
+                                       &Incoming->getModule()->getDataLayout());
   }
 
   if (!NewInit)
-    NewInit =
-        Builder.CreateVectorInterleave({Init, Constant::getNullValue(VTy)});
+    NewInit = Builder.CreateVectorInterleave(
+        {Init,
+         Constant::getNullValue(VTy, &Incoming->getModule()->getDataLayout())});
 
   NewPHI->addIncoming(NewInit, Incoming);
   NewPHI->addIncoming(OperationReplacement, BackEdge);
diff --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
index cc0584ef1d63e..9d77aeaeda6ce 100644
--- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
@@ -377,7 +377,7 @@ bool IRTranslator::translateCompare(const User &U,
     MIRBuilder.buildICmp(Pred, Res, Op0, Op1, Flags);
   else if (Pred == CmpInst::FCMP_FALSE)
     MIRBuilder.buildCopy(
-        Res, getOrCreateVReg(*Constant::getNullValue(U.getType())));
+        Res, getOrCreateVReg(*Constant::getNullValue(U.getType(), DL)));
   else if (Pred == CmpInst::FCMP_TRUE)
     MIRBuilder.buildCopy(
         Res, getOrCreateVReg(*Constant::getAllOnesValue(U.getType())));
diff --git a/llvm/lib/CodeGen/IntrinsicLowering.cpp b/llvm/lib/CodeGen/IntrinsicLowering.cpp
index 1518ead7698be..508dddb06a006 100644
--- a/llvm/lib/CodeGen/IntrinsicLowering.cpp
+++ b/llvm/lib/CodeGen/IntrinsicLowering.cpp
@@ -282,7 +282,8 @@ void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) {
                "save" : "restore") << " intrinsic.\n";
     Warned = true;
     if (Callee->getIntrinsicID() == Intrinsic::stacksave)
-      CI->replaceAllUsesWith(Constant::getNullValue(CI->getType()));
+      CI->replaceAllUsesWith(Constant::getNullValue(
+          CI->getType(), &CI->getModule()->getDataLayout()));
     break;
   }
 
diff --git a/llvm/lib/CodeGen/ShadowStackGCLowering.cpp b/llvm/lib/CodeGen/ShadowStackGCLowering.cpp
index 34da16faee053..f1346f9c67689 100644
--- a/llvm/lib/CodeGen/ShadowStackGCLowering.cpp
+++ b/llvm/lib/CodeGen/ShadowStackGCLowering.cpp
@@ -251,9 +251,11 @@ bool ShadowStackGCLoweringImpl::doInitialization(Module &M) {
     // linkage!
     Head = new GlobalVariable(
         M, StackEntryPtrTy, false, GlobalValue::LinkOnceAnyLinkage,
-        Constant::getNullValue(StackEntryPtrTy), "llvm_gc_root_chain");
+        Constant::getNullValue(StackEntryPtrTy, &M.getDataLayout()),
+        "llvm_gc_root_chain");
   } else if (Head->hasExternalLinkage() && Head->isDeclaration()) {
-    Head->setInitializer(Constant::getNullValue(StackEntryPtrTy));
+    Head->setInitializer(
+        Constant::getNullValue(StackEntryPtrTy, &M.getDataLayout()));
     Head->setLinkage(GlobalValue::LinkOnceAnyLinkage);
   }
 
diff --git a/llvm/lib/ExecutionEngine/ExecutionEngine.cpp b/llvm/lib/ExecutionEngine/ExecutionEngine.cpp
index 38aed020bb119..f651072360640 100644
--- a/llvm/lib/ExecutionEngine/ExecutionEngine.cpp
+++ b/llvm/lib/ExecutionEngine/ExecutionEngine.cpp
@@ -892,7 +892,7 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) {
   if (auto *TETy = dyn_cast<TargetExtType>(C->getType())) {
     assert(TETy->hasProperty(TargetExtType::HasZeroInit) && C->isNullValue() &&
            "TargetExtType only supports null constant value");
-    C = Constant::getNullValue(TETy->getLayoutType());
+    C = Constant::getNullValue(TETy->getLayoutType(), &DL);
   }
 
   // Otherwise, we have a simple constant.
diff --git a/llvm/lib/ExecutionEngine/Orc/ReOptimizeLayer.cpp b/llvm/lib/ExecutionEngine/Orc/ReOptimizeLayer.cpp
index ef84a952ddc82..02a4060eed096 100644
--- a/llvm/lib/ExecutionEngine/Orc/ReOptimizeLayer.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/ReOptimizeLayer.cpp
@@ -183,9 +183,10 @@ Error ReOptimizeLayer::reoptimizeIfCallFrequent(ReOptimizeLayer &Parent,
                                                 ThreadSafeModule &TSM) {
   return TSM.withModuleDo([&](Module &M) -> Error {
     Type *I64Ty = Type::getInt64Ty(M.getContext());
-    GlobalVariable *Counter = new GlobalVariable(
-        M, I64Ty, false, GlobalValue::InternalLinkage,
-        Constant::getNullValue(I64Ty), "__orc_reopt_counter");
+    GlobalVariable *Counter =
+        new GlobalVariable(M, I64Ty, false, GlobalValue::InternalLinkage,
+                           Constant::getNullValue(I64Ty, &M.getDataLayout()),
+                           "__orc_reopt_counter");
     for (auto &F : M) {
       if (F.isDeclaration())
         continue;
diff --git a/llvm/lib/Frontend/Offloading/OffloadWrapper.cpp b/llvm/lib/Frontend/Offloading/OffloadWrapper.cpp
index 779743aeeeef9..49a2f5565d5c4 100644
--- a/llvm/lib/Frontend/Offloading/OffloadWrapper.cpp
+++ b/llvm/lib/Frontend/Offloading/OffloadWrapper.cpp
@@ -915,7 +915,8 @@ class SYCLWrapper {
 
       GlobalVariable *GV = emitOffloadingEntry(
           M, /*Kind*/ OffloadKind::OFK_SYCL,
-          Constant::getNullValue(PointerType::getUnqual(C)), Name, /*Size*/ 0,
+          Constant::getNullValue(PointerType::getUnqual(C), &M.getDataLayout()),
+          Name, /*Size*/ 0,
           /*Flags*/ 0, /*Data*/ 0);
       EntriesInits.push_back(GV->getInitializer());
     }
@@ -958,8 +959,8 @@ class SYCLWrapper {
 
     // Note: NULL for now.
     std::pair<Constant *, Constant *> PropertiesConstants = {
-        Constant::getNullValue(PointerType::getUnqual(C)),
-        Constant::getNullValue(PointerType::getUnqual(C))};
+        Constant::getNullValue(PointerType::getUnqual(C), &M.getDataLayout()),
+        Constant::getNullValue(PointerType::getUnqual(C), &M.getDataLayout())};
 
     StringRef RawImage = OB.getImage();
     std::pair<Constant *, Constant *> Binary = addArrayToModule(
@@ -996,8 +997,10 @@ class SYCLWrapper {
                            Twine(OffloadKindTag) + "device_images");
     ImagesGV->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
 
-    Constant *EntriesB = Constant::getNullValue(PointerType::getUnqual(C));
-    Constant *EntriesE = Constant::getNullValue(PointerType::getUnqual(C));
+    Constant *EntriesB =
+        Constant::getNullValue(PointerType::getUnqual(C), &M.getDataLayout());
+    Constant *EntriesE =
+        Constant::getNullValue(PointerType::getUnqual(C), &M.getDataLayout());
     static constexpr uint16_t BinDescStructVersion = 1;
     Constant *DescInit = ConstantStruct::get(
         SyclBinDescTy,
diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index 052ca43a34d65..cd9d92cc4125f 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -538,7 +538,9 @@ void OpenMPIRBuilder::getKernelArgsVector(TargetKernelArgs &KernelArgs,
   Value *PointerNum = Builder.getInt32(KernelArgs.NumTargetItems);
   auto Int32Ty = Type::getInt32Ty(Builder.getContext());
   constexpr size_t MaxDim = 3;
-  Value *ZeroArray = Constant::getNullValue(ArrayType::get(Int32Ty, MaxDim));
+  Value *ZeroArray = Constant::getNullValue(
+      ArrayType::get(Int32Ty, MaxDim),
+      &Builder.GetInsertBlock()->getModule()->getDataLayout());
 
   Value *HasNoWaitFlag = Builder.getInt64(KernelArgs.HasNoWait);
 
@@ -1429,7 +1431,8 @@ static void targetParallelCallback(
 
   Builder.SetInsertPoint(CI);
   Type *PtrTy = OMPIRBuilder->VoidPtr;
-  Value *NullPtrValue = Constant::getNullValue(PtrTy);
+  Value *NullPtrValue =
+      Constant::getNullValue(PtrTy, &OMPIRBuilder->M.getDataLayout());
 
   // Add alloca for kernel args
   OpenMPIRBuilder ::InsertPointTy CurrentIP = Builder.saveIP();
@@ -1552,7 +1555,8 @@ hostParallelCallback(OpenMPIRBuilder *OMPIRBuilder, Function &OutlinedFn,
   // If there are no arguments, pass a null pointer.
   auto PtrTy = OMPIRBuilder->VoidPtr;
   if (IfCondition && NumCapturedVars == 0) {
-    Value *NullPtrValue = Constant::getNullValue(PtrTy);
+    Value *NullPtrValue =
+        Constant::getNullValue(PtrTy, &OMPIRBuilder->M.getDataLayout());
     RealArgs.push_back(NullPtrValue);
   }
 
@@ -2037,7 +2041,8 @@ Expected<Value *> OpenMPIRBuilder::createTaskDuplicationFunction(
   unsigned ProgramAddressSpace = M.getDataLayout().getProgramAddressSpace();
   if (!DupCB)
     return Constant::getNullValue(
-        PointerType::get(Builder.getContext(), ProgramAddressSpace));
+        PointerType::get(Builder.getContext(), ProgramAddressSpace),
+        &M.getDataLayout());
 
   // From OpenMP Runtime p_task_dup_t:
   // Routine optionally generated by the compiler for setting the lastprivate
@@ -3272,9 +3277,10 @@ Expected<Function *> OpenMPIRBuilder::emitInterWarpCopyFunction(
         CntAddr = Builder.CreateAddrSpaceCast(CntAddr, Builder.getPtrTy(),
                                               CntAddr->getName() + ".ascast");
         Builder.restoreIP(CodeGenIP);
-        Builder.CreateStore(Constant::getNullValue(Builder.getInt32Ty()),
-                            CntAddr,
-                            /*Volatile=*/false);
+        Builder.CreateStore(
+            Constant::getNullValue(Builder.getInt32Ty(), &M.getDataLayout()),
+            CntAddr,
+            /*Volatile=*/false);
         PrecondBB = BasicBlock::Create(Ctx, "precond");
         ExitBB = BasicBlock::Create(Ctx, "exit");
         BasicBlock *BodyBB = BasicBlock::Create(Ctx, "body");
@@ -5882,7 +5888,8 @@ static void workshareLoopTargetCallback(
   if (OutlinedFnCallInstruction->arg_size() > 1)
     LoopBodyArg = OutlinedFnCallInstruction->getArgOperand(1);
   else
-    LoopBodyArg = Constant::getNullValue(Builder.getPtrTy());
+    LoopBodyArg = Constant::getNullValue(Builder.getPtrTy(),
+                                         &OMPIRBuilder->M.getDataLayout());
   OutlinedFnCallInstruction->eraseFromParent();
 
   createTargetLoopWorkshareCall(OMPIRBuilder, LoopType, Preheader, Ident,
@@ -7966,7 +7973,8 @@ Constant *OpenMPIRBuilder::createOutlinedFunctionID(Function *OutlinedFn,
 
   return new GlobalVariable(
       M, Builder.getInt8Ty(), /*isConstant=*/true, GlobalValue::WeakAnyLinkage,
-      Constant::getNullValue(Builder.getInt8Ty()), EntryFnIDName);
+      Constant::getNullValue(Builder.getInt8Ty(), &M.getDataLayout()),
+      EntryFnIDName);
 }
 
 Constant *OpenMPIRBuilder::createTargetRegionEntryAddr(Function *OutlinedFn,
@@ -7978,7 +7986,8 @@ Constant *OpenMPIRBuilder::createTargetRegionEntryAddr(Function *OutlinedFn,
          "Named kernel already exists?");
   return new GlobalVariable(
       M, Builder.getInt8Ty(), /*isConstant=*/true, GlobalValue::InternalLinkage,
-      Constant::getNullValue(Builder.getInt8Ty()), EntryFnName);
+      Constant::getNullValue(Builder.getInt8Ty(), &M.getDataLayout()),
+      EntryFnName);
 }
 
 Error OpenMPIRBuilder::emitTargetRegionFunction(
@@ -8080,10 +8089,11 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createTargetData(
       auto TaskBodyCB = [&](Value *, Value *,
                             IRBuilderBase::InsertPoint) -> Error {
         if (Info.HasNoWait) {
-          OffloadingArgs.append({llvm::Constant::getNullValue(Int32),
-                                 llvm::Constant::getNullValue(VoidPtr),
-                                 llvm::Constant::getNullValue(Int32),
-                                 llvm::Constant::getNullValue(VoidPtr)});
+          OffloadingArgs.append(
+              {llvm::Constant::getNullValue(Int32, &M.getDataLayout()),
+               llvm::Constant::getNullValue(VoidPtr, &M.getDataLayout()),
+               llvm::Constant::getNullValue(Int32, &M.getDataLayout()),
+               llvm::Constant::getNullValue(VoidPtr, &M.getDataLayout())});
         }
 
         createRuntimeFunctionCall(getOrCreateRuntimeFunctionPtr(*MapperFunc),
@@ -9409,10 +9419,10 @@ GlobalVariable *OpenMPIRBuilder::getOrCreateInternalVariable(
     auto Linkage = this->M.getTargetTriple().getArch() == Triple::wasm32
                        ? GlobalValue::InternalLinkage
                        : GlobalValue::CommonLinkage;
-    auto *GV = new GlobalVariable(M, Ty, /*IsConstant=*/false, Linkage,
-                                  Constant::getNullValue(Ty), Elem.first(),
-                                  /*InsertBefore=*/nullptr,
-                                  GlobalValue::NotThreadLocal, AddressSpaceVal);
+    auto *GV = new GlobalVariable(
+        M, Ty, /*IsConstant=*/false, Linkage,
+        Constant::getNullValue(Ty, &M.getDataLayout()), Elem.first(),
+        /*InsertBefore=*/nullptr, GlobalValue::NotThreadLocal, AddressSpaceVal);
     const llvm::Align TypeAlign = DL.getABITypeAlign(Ty);
     const llvm::Align PtrAlign = DL.getPointerABIAlignment(AddressSpaceVal);
     GV->setAlignment(std::max(TypeAlign, PtrAlign));
@@ -9430,8 +9440,8 @@ Value *OpenMPIRBuilder::getOMPCriticalRegionLock(StringRef CriticalName) {
 
 Value *OpenMPIRBuilder::getSizeInBytes(Value *BasePtr) {
   LLVMContext &Ctx = Builder.getContext();
-  Value *Null =
-      Constant::getNullValue(PointerType::getUnqual(BasePtr->getContext()));
+  Value *Null = Constant::getNullValue(
+      PointerType::getUnqual(BasePtr->getContext()), &M.getDataLayout());
   Value *SizeGep =
       Builder.CreateGEP(BasePtr->getType(), Null, Builder.getInt32(1));
   Value *SizePtrToInt = Builder.CreatePtrToInt(SizeGep, Type::getInt64Ty(Ctx));
@@ -9492,8 +9502,8 @@ void OpenMPIRBuilder::emitMapperCall(const LocationDescription &Loc,
   Value *ArgSizesGEP =
       Builder.CreateInBoundsGEP(ArrI64Ty, MapperAllocas.ArgSizes,
                                 {Builder.getInt32(0), Builder.getInt32(0)});
-  Value *NullPtr =
-      Constant::getNullValue(PointerType::getUnqual(Int8Ptr->getContext()));
+  Value *NullPtr = Constant::getNullValue(
+      PointerType::getUnqual(Int8Ptr->getContext()), &M.getDataLayout());
   createRuntimeFunctionCall(MapperFunc, {SrcLocInfo, Builder.getInt64(DeviceID),
                                          Builder.getInt32(NumOperands),
                                          ArgsBaseGEP, ArgsGEP, ArgSizesGEP,
@@ -9779,9 +9789,10 @@ Expected<Function *> OpenMPIRBuilder::emitUserDefinedMapper(
     Value *CurBaseArg = Info->BasePointers[I];
     Value *CurBeginArg = Info->Pointers[I];
     Value *CurSizeArg = Info->Sizes[I];
-    Value *CurNameArg = Info->Names.size()
-                            ? Info->Names[I]
-                            : Constant::getNullValue(Builder.getPtrTy());
+    Value *CurNameArg =
+        Info->Names.size()
+            ? Info->Names[I]
+            : Constant::getNullValue(Builder.getPtrTy(), &M.getDataLayout());
 
     // Extract the MEMBER_OF field from the map type.
     Value *OriMapType = Builder.getInt64(
@@ -10016,8 +10027,8 @@ Error OpenMPIRBuilder::emitOffloadingArrays(
     Info.RTArgs.MapNamesArray = MapNamesArrayGbl;
     Info.EmitDebug = true;
   } else {
-    Info.RTArgs.MapNamesArray =
-        Constant::getNullValue(PointerType::getUnqual(Builder.getContext()));
+    Info.RTArgs.MapNamesArray = Constant::getNullValue(
+        PointerType::getUnqual(Builder.getContext()), &M.getDataLayout());
     Info.EmitDebug = false;
   }
 
@@ -11240,7 +11251,8 @@ void OpenMPIRBuilder::createOffloadEntriesAndInfoMetadata(
   if (Config.hasRequiresFlags() && !Config.isTargetDevice())
     offloading::emitOffloadingEntry(
         M, object::OffloadKind::OFK_OpenMP,
-        Constant::getNullValue(PointerType::getUnqual(M.getContext())),
+        Constant::getNullValue(PointerType::getUnqual(M.getContext()),
+                               &M.getDataLayout()),
         ".requires", /*Size=*/0,
         OffloadEntriesInfoManager::OMPTargetGlobalRegisterRequires,
         Config.getRequiresFlags());
diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp
index d89d4217989be..ca8e196d39d0a 100644
--- a/llvm/lib/IR/AutoUpgrade.cpp
+++ b/llvm/lib/IR/AutoUpgrade.cpp
@@ -1944,7 +1944,8 @@ static Value *upgradeX86PSLLDQIntrinsics(IRBuilder<> &Builder, Value *Op,
   Op = Builder.CreateBitCast(Op, VecTy, "cast");
 
   // We'll be shuffling in zeroes.
-  Value *Res = Constant::getNullValue(VecTy);
+  Value *Res = Constant::getNullValue(
+      VecTy, &Builder.GetInsertBlock()->getModule()->getDataLayout());
 
   // If shift is less than 16, emit a shuffle to move the bytes. Otherwise,
   // we'll just return the zero vector.
@@ -1978,7 +1979,8 @@ static Value *upgradeX86PSRLDQIntrinsics(IRBuilder<> &Builder, Value *Op,
   Op = Builder.CreateBitCast(Op, VecTy, "cast");
 
   // We'll be shuffling in zeroes.
-  Value *Res = Constant::getNullValue(VecTy);
+  Value *Res = Constant::getNullValue(
+      VecTy, &Builder.GetInsertBlock()->getModule()->getDataLayout());
 
   // If shift is less than 16, emit a shuffle to move the bytes. Otherwise,
   // we'll just return the zero vector.
@@ -2067,14 +2069,18 @@ static Value *upgradeX86ALIGNIntrinsics(IRBuilder<> &Builder, Value *Op0,
   // If palignr is shifting the pair of vectors more than the size of two
   // lanes, emit zero.
   if (ShiftVal >= 32)
-    return llvm::Constant::getNullValue(Op0->getType());
+    return llvm::Constant::getNullValue(
+        Op0->getType(),
+        &Builder.GetInsertBlock()->getModule()->getDataLayout());
 
   // If palignr is shifting the pair of input vectors more than one lane,
   // but less than two lanes, convert to shifting in zeroes.
   if (ShiftVal > 16) {
     ShiftVal -= 16;
     Op1 = Op0;
-    Op0 = llvm::Constant::getNullValue(Op0->getType());
+    Op0 = llvm::Constant::getNullValue(
+        Op0->getType(),
+        &Builder.GetInsertBlock()->getModule()->getDataLayout());
   }
 
   int Indices[64];
@@ -2222,7 +2228,8 @@ static Value *upgradeX86vpcom(IRBuilder<> &Builder, CallBase &CI, unsigned Imm,
     Pred = ICmpInst::ICMP_NE;
     break;
   case 0x6:
-    return Constant::getNullValue(Ty); // FALSE
+    return Constant::getNullValue(Ty,
+                                  &CI.getModule()->getDataLayout()); // FALSE
   case 0x7:
     return Constant::getAllOnesValue(Ty); // TRUE
   default:
@@ -2361,9 +2368,12 @@ static Value *applyX86MaskOn1BitsVec(IRBuilder<> &Builder, Value *Vec,
       Indices[i] = i;
     for (unsigned i = NumElts; i != 8; ++i)
       Indices[i] = NumElts + i % NumElts;
-    Vec = Builder.CreateShuffleVector(Vec,
-                                      Constant::getNullValue(Vec->getType()),
-                                      Indices);
+    Vec = Builder.CreateShuffleVector(
+        Vec,
+        Constant::getNullValue(
+            Vec->getType(),
+            &Builder.GetInsertBlock()->getModule()->getDataLayout()),
+        Indices);
   }
   return Builder.CreateBitCast(Vec, Builder.getIntNTy(std::max(NumElts, 8U)));
 }
@@ -2376,7 +2386,8 @@ static Value *upgradeMaskedCompare(IRBuilder<> &Builder, CallBase &CI,
   Value *Cmp;
   if (CC == 3) {
     Cmp = Constant::getNullValue(
-        FixedVectorType::get(Builder.getInt1Ty(), NumElts));
+        FixedVectorType::get(Builder.getInt1Ty(), NumElts),
+        &CI.getModule()->getDataLayout());
   } else if (CC == 7) {
     Cmp = Constant::getAllOnesValue(
         FixedVectorType::get(Builder.getInt1Ty(), NumElts));
@@ -2686,7 +2697,10 @@ static Value *upgradeNVVMIntrinsicCall(StringRef Name, CallBase *CI,
     Value *Arg = CI->getArgOperand(0);
     Value *Neg = Builder.CreateNeg(Arg, "neg");
     Value *Cmp = Builder.CreateICmpSGE(
-        Arg, llvm::Constant::getNullValue(Arg->getType()), "abs.cond");
+        Arg,
+        llvm::Constant::getNullValue(Arg->getType(),
+                                     &CI->getModule()->getDataLayout()),
+        "abs.cond");
     Rep = Builder.CreateSelect(Cmp, Arg, Neg, "abs");
   } else if (Name == "abs.bf16" || Name == "abs.bf16x2") {
     Type *Ty = (Name == "abs.bf16")
@@ -2942,7 +2956,8 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
     Value *Mask = CI->getArgOperand(2);
     Rep = Builder.CreateAnd(Op0, Op1);
     llvm::Type *Ty = Op0->getType();
-    Value *Zero = llvm::Constant::getNullValue(Ty);
+    Value *Zero =
+        llvm::Constant::getNullValue(Ty, &CI->getModule()->getDataLayout());
     ICmpInst::Predicate Pred = Name.starts_with("avx512.ptestm")
                                    ? ICmpInst::ICMP_NE
                                    : ICmpInst::ICMP_EQ;
@@ -3121,7 +3136,8 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
              Name.starts_with("avx512.cvtd2mask.") ||
              Name.starts_with("avx512.cvtq2mask.")) {
     Value *Op = CI->getArgOperand(0);
-    Value *Zero = llvm::Constant::getNullValue(Op->getType());
+    Value *Zero = llvm::Constant::getNullValue(
+        Op->getType(), &CI->getModule()->getDataLayout());
     Rep = Builder.CreateICmp(ICmpInst::ICMP_SLT, Op, Zero);
     Rep = applyX86MaskOn1BitsVec(Builder, Rep, nullptr);
   } else if (Name == "ssse3.pabs.b.128" || Name == "ssse3.pabs.w.128" ||
@@ -3427,7 +3443,8 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
     ElementCount EC = cast<VectorType>(CI->getType())->getElementCount();
     Type *MaskTy = VectorType::get(Type::getInt32Ty(C), EC);
     SmallVector<int, 8> M;
-    ShuffleVectorInst::getShuffleMask(Constant::getNullValue(MaskTy), M);
+    ShuffleVectorInst::getShuffleMask(
+        Constant::getNullValue(MaskTy, &CI->getModule()->getDataLayout()), M);
     Rep = Builder.CreateShuffleVector(Op, M);
 
     if (CI->arg_size() == 3)
@@ -4146,8 +4163,10 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
 
     Rep = Builder.CreateIntrinsic(Intrinsic::fma, Ops[0]->getType(), Ops);
 
-    Rep = Builder.CreateInsertElement(Constant::getNullValue(CI->getType()),
-                                      Rep, (uint64_t)0);
+    Rep = Builder.CreateInsertElement(
+        Constant::getNullValue(CI->getType(),
+                               &CI->getModule()->getDataLayout()),
+        Rep, (uint64_t)0);
   } else if (Name.starts_with("avx512.mask.vfmadd.s") ||
              Name.starts_with("avx512.maskz.vfmadd.s") ||
              Name.starts_with("avx512.mask3.vfmadd.s") ||
@@ -4189,9 +4208,11 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
       Rep = Builder.CreateFMA(A, B, C);
     }
 
-    Value *PassThru = IsMaskZ   ? Constant::getNullValue(Rep->getType())
-                      : IsMask3 ? C
-                                : A;
+    Value *PassThru =
+        IsMaskZ   ? Constant::getNullValue(Rep->getType(),
+                                           &CI->getModule()->getDataLayout())
+        : IsMask3 ? C
+                  : A;
 
     // For Mask3 with NegAcc, we need to create a new extractelement that
     // avoids the negation above.
@@ -4242,9 +4263,11 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
       Rep = Builder.CreateFMA(A, B, C);
     }
 
-    Value *PassThru = IsMaskZ   ? llvm::Constant::getNullValue(CI->getType())
-                      : IsMask3 ? CI->getArgOperand(2)
-                                : CI->getArgOperand(0);
+    Value *PassThru =
+        IsMaskZ ? llvm::Constant::getNullValue(
+                      CI->getType(), &CI->getModule()->getDataLayout())
+        : IsMask3 ? CI->getArgOperand(2)
+                  : CI->getArgOperand(0);
 
     Rep = emitX86Select(Builder, CI->getArgOperand(3), Rep, PassThru);
   } else if (Name.starts_with("fma.vfmsubadd.p")) {
@@ -4311,9 +4334,11 @@ static Value *upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F,
       Rep = Builder.CreateShuffleVector(Even, Odd, Idxs);
     }
 
-    Value *PassThru = IsMaskZ   ? llvm::Constant::getNullValue(CI->getType())
-                      : IsMask3 ? CI->getArgOperand(2)
-                                : CI->getArgOperand(0);
+    Value *PassThru =
+        IsMaskZ ? llvm::Constant::getNullValue(
+                      CI->getType(), &CI->getModule()->getDataLayout())
+        : IsMask3 ? CI->getArgOperand(2)
+                  : CI->getArgOperand(0);
 
     Rep = emitX86Select(Builder, CI->getArgOperand(3), Rep, PassThru);
   } else if (Name.starts_with("avx512.mask.pternlog.") ||
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp
index 42a85d3ca2d99..c3803141e5561 100644
--- a/llvm/lib/IR/ConstantFold.cpp
+++ b/llvm/lib/IR/ConstantFold.cpp
@@ -142,7 +142,7 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, Constant *V,
     // [us]itofp(undef) = 0, because the result value is bounded.
     if (opc == Instruction::ZExt || opc == Instruction::SExt ||
         opc == Instruction::UIToFP || opc == Instruction::SIToFP)
-      return Constant::getNullValue(DestTy);
+      return Constant::getNullValue(DestTy, DL);
     return UndefValue::get(DestTy);
   }
 
@@ -161,7 +161,7 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, Constant *V,
           return nullptr;
       }
     }
-    return Constant::getNullValue(DestTy);
+    return Constant::getNullValue(DestTy, DL);
   }
 
   // If the cast operand is a constant expression, there's a few things we can
@@ -1129,7 +1129,7 @@ Constant *llvm::ConstantFoldCompareInstruction(CmpInst::Predicate Predicate,
 
   // Fold FCMP_FALSE/FCMP_TRUE unconditionally.
   if (Predicate == FCmpInst::FCMP_FALSE)
-    return Constant::getNullValue(ResultTy);
+    return Constant::getNullValue(ResultTy, DL);
 
   if (Predicate == FCmpInst::FCMP_TRUE)
     return Constant::getAllOnesValue(ResultTy);
@@ -1174,7 +1174,7 @@ Constant *llvm::ConstantFoldCompareInstruction(CmpInst::Predicate Predicate,
         return Constant::getAllOnesValue(ResultTy);
       // C1 < 0 --> false
       if (Predicate == ICmpInst::ICMP_ULT)
-        return Constant::getNullValue(ResultTy);
+        return Constant::getNullValue(ResultTy, DL);
     }
   }
 
diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
index 2efd9490795dd..35ba7b894702d 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -32877,7 +32877,8 @@ Value *AArch64TargetLowering::createComplexDeinterleavingIR(
     Value *Accumulator) const {
   VectorType *Ty = cast<VectorType>(InputA->getType());
   if (Accumulator == nullptr)
-    Accumulator = Constant::getNullValue(Ty);
+    Accumulator = Constant::getNullValue(
+        Ty, &B.GetInsertBlock()->getModule()->getDataLayout());
   bool IsScalable = Ty->isScalableTy();
   bool IsInt = Ty->getElementType()->isIntegerTy();
 
diff --git a/llvm/lib/Target/AArch64/AArch64StackTagging.cpp b/llvm/lib/Target/AArch64/AArch64StackTagging.cpp
index 3e099e8216266..7e1fab42975c6 100644
--- a/llvm/lib/Target/AArch64/AArch64StackTagging.cpp
+++ b/llvm/lib/Target/AArch64/AArch64StackTagging.cpp
@@ -232,10 +232,12 @@ class InitializerBuilder {
       if (Offset > LastOffset)
         emitZeroes(IRB, LastOffset, Offset - LastOffset);
 
-      Value *Store1 = I1 == Out.end() ? Constant::getNullValue(IRB.getInt64Ty())
-                                      : I1->second;
-      Value *Store2 = I2 == Out.end() ? Constant::getNullValue(IRB.getInt64Ty())
-                                      : I2->second;
+      Value *Store1 = I1 == Out.end()
+                          ? Constant::getNullValue(IRB.getInt64Ty(), DL)
+                          : I1->second;
+      Value *Store2 = I2 == Out.end()
+                          ? Constant::getNullValue(IRB.getInt64Ty(), DL)
+                          : I2->second;
       emitPair(IRB, Offset, Store1, Store2);
       LastOffset = Offset + 16;
     }
@@ -485,7 +487,7 @@ Instruction *AArch64StackTagging::insertBaseTaggedPointer(
   IRBuilder<> IRB(&PrologueBB->front());
   Instruction *Base =
       IRB.CreateIntrinsic(Intrinsic::aarch64_irg_sp, {},
-                          {Constant::getNullValue(IRB.getInt64Ty())});
+                          {Constant::getNullValue(IRB.getInt64Ty(), DL)});
   Base->setName("basetag");
   const Triple &TargetTriple = M.getTargetTriple();
   // This ABI will make it into Android API level 35.
@@ -583,8 +585,8 @@ bool AArch64StackTagging::runOnFunction(Function &Fn) {
     IRBuilder<> IRB(Info.AI->getNextNode());
     Instruction *TagPCall =
         IRB.CreateIntrinsic(Intrinsic::aarch64_tagp, {Info.AI->getType()},
-                            {Constant::getNullValue(Info.AI->getType()), Base,
-                             ConstantInt::get(IRB.getInt64Ty(), Tag)});
+                            {Constant::getNullValue(Info.AI->getType(), DL),
+                             Base, ConstantInt::get(IRB.getInt64Ty(), Tag)});
     if (Info.AI->hasName())
       TagPCall->setName(Info.AI->getName() + ".tag");
     // Does not replace metadata, so we don't have to handle DbgVariableRecords.
diff --git a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
index a5dbd96205a59..4568f7d00d79b 100644
--- a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
+++ b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
@@ -1803,7 +1803,9 @@ simplifySVEIntrinsic(InstCombiner &IC, IntrinsicInst &II,
 
     if (IInfo.inactiveLanesAreUnused()) {
       if (IInfo.resultIsZeroInitialized())
-        IC.replaceInstUsesWith(II, Constant::getNullValue(II.getType()));
+        IC.replaceInstUsesWith(
+            II, Constant::getNullValue(II.getType(),
+                                       &II.getModule()->getDataLayout()));
 
       return IC.eraseInstFromFunction(II);
     }
@@ -2047,7 +2049,8 @@ static std::optional<Instruction *> instCombineSVECmpNE(InstCombiner &IC,
 
   // If all bits are zero bail early with an empty predicate
   if (PredicateBits == 0) {
-    auto *PFalse = Constant::getNullValue(II.getType());
+    auto *PFalse =
+        Constant::getNullValue(II.getType(), &II.getModule()->getDataLayout());
     PFalse->takeName(&II);
     return IC.replaceInstUsesWith(II, PFalse);
   }
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp b/llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp
index 82de8cf169b48..e66677d8eae8f 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp
@@ -976,7 +976,7 @@ GCNTTIImpl::instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const {
       return IC.replaceInstUsesWith(II, PoisonValue::get(Ty));
 
     if(IC.getSimplifyQuery().isUndefValue(Arg))
-      return IC.replaceInstUsesWith(II, Constant::getNullValue(Ty));
+      return IC.replaceInstUsesWith(II, Constant::getNullValue(Ty, &DL));
 
     ConstantInt *CArg = dyn_cast<ConstantInt>(II.getArgOperand(0));
     if (!CArg)
@@ -1409,7 +1409,8 @@ GCNTTIImpl::instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const {
     if (auto *Src = dyn_cast<ConstantInt>(Arg)) {
       if (Src->isZero()) {
         // amdgcn.ballot(i1 0) is zero.
-        return IC.replaceInstUsesWith(II, Constant::getNullValue(II.getType()));
+        return IC.replaceInstUsesWith(
+            II, Constant::getNullValue(II.getType(), &DL));
       }
     }
     if (ST->isWave32() && II.getType()->getIntegerBitWidth() == 64) {
diff --git a/llvm/lib/Target/AMDGPU/AMDGPULowerBufferFatPointers.cpp b/llvm/lib/Target/AMDGPU/AMDGPULowerBufferFatPointers.cpp
index 37ca2aff005c9..fbb6018733c00 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPULowerBufferFatPointers.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPULowerBufferFatPointers.cpp
@@ -2031,13 +2031,14 @@ PtrParts SplitPtrStructs::visitAddrSpaceCastInst(AddrSpaceCastInst &I) {
   auto *ResTy = cast<StructType>(I.getType());
   Type *RsrcTy = ResTy->getElementType(0);
   Type *OffTy = ResTy->getElementType(1);
-  Value *ZeroOff = Constant::getNullValue(OffTy);
+  const auto &DL = I.getDataLayout();
+  Value *ZeroOff = Constant::getNullValue(OffTy, &DL);
 
   // Special case for null pointers, undef, and poison, which can be created by
   // address space propagation.
   auto *InConst = dyn_cast<Constant>(In);
   if (InConst && InConst->isNullValue()) {
-    Value *NullRsrc = Constant::getNullValue(RsrcTy);
+    Value *NullRsrc = Constant::getNullValue(RsrcTy, &DL);
     SplitUsers.insert(&I);
     return {NullRsrc, ZeroOff};
   }
@@ -2240,7 +2241,7 @@ PtrParts SplitPtrStructs::visitIntrinsicInst(IntrinsicInst &I) {
                                       {Base, Stride, NumRecords, Flags});
     copyMetadata(Rsrc, &I);
     Rsrc->takeName(&I);
-    Value *Zero = Constant::getNullValue(OffType);
+    Value *Zero = Constant::getNullValue(OffType, &I.getDataLayout());
     SplitUsers.insert(&I);
     return {Rsrc, Zero};
   }
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp b/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
index 393fd1a187d68..f21f41d172409 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
@@ -1626,7 +1626,8 @@ bool AMDGPUPromoteAllocaImpl::tryPromoteAllocaToLDS(
   TID = Builder.CreateAdd(TID, TIdZ);
 
   LLVMContext &Context = Mod->getContext();
-  Value *Indices[] = {Constant::getNullValue(Type::getInt32Ty(Context)), TID};
+  Value *Indices[] = {Constant::getNullValue(Type::getInt32Ty(Context), &DL),
+                      TID};
 
   Value *Offset = Builder.CreateInBoundsGEP(GVTy, GV, Indices);
   AA.Alloca->mutateType(Offset->getType());
@@ -1644,10 +1645,10 @@ bool AMDGPUPromoteAllocaImpl::tryPromoteAllocaToLDS(
 
         Type *NewTy = LHS->getType()->getWithNewType(NewPtrTy);
         if (isa<ConstantPointerNull, ConstantAggregateZero>(LHS))
-          CI->setOperand(0, Constant::getNullValue(NewTy));
+          CI->setOperand(0, Constant::getNullValue(NewTy, &DL));
 
         if (isa<ConstantPointerNull, ConstantAggregateZero>(RHS))
-          CI->setOperand(1, Constant::getNullValue(NewTy));
+          CI->setOperand(1, Constant::getNullValue(NewTy, &DL));
 
         continue;
       }
@@ -1665,15 +1666,15 @@ bool AMDGPUPromoteAllocaImpl::tryPromoteAllocaToLDS(
       // Adjust the types of any constant operands.
       if (SelectInst *SI = dyn_cast<SelectInst>(V)) {
         if (isa<ConstantPointerNull, ConstantAggregateZero>(SI->getOperand(1)))
-          SI->setOperand(1, Constant::getNullValue(NewTy));
+          SI->setOperand(1, Constant::getNullValue(NewTy, &DL));
 
         if (isa<ConstantPointerNull, ConstantAggregateZero>(SI->getOperand(2)))
-          SI->setOperand(2, Constant::getNullValue(NewTy));
+          SI->setOperand(2, Constant::getNullValue(NewTy, &DL));
       } else if (PHINode *Phi = dyn_cast<PHINode>(V)) {
         for (unsigned I = 0, E = Phi->getNumIncomingValues(); I != E; ++I) {
           if (isa<ConstantPointerNull, ConstantAggregateZero>(
                   Phi->getIncomingValue(I)))
-            Phi->setIncomingValue(I, Constant::getNullValue(NewTy));
+            Phi->setIncomingValue(I, Constant::getNullValue(NewTy, &DL));
         }
       }
 
diff --git a/llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp b/llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp
index c4bf097e5a0f8..67654ee174e63 100644
--- a/llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp
+++ b/llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp
@@ -1022,7 +1022,8 @@ static Value *expandSignIntrinsic(CallInst *Orig) {
   Type *Ty = X->getType();
   Type *ScalarTy = Ty->getScalarType();
   Type *RetTy = Orig->getType();
-  Constant *Zero = Constant::getNullValue(Ty);
+  Constant *Zero =
+      Constant::getNullValue(Ty, &Orig->getModule()->getDataLayout());
 
   IRBuilder<> Builder(Orig);
 
diff --git a/llvm/lib/Target/DirectX/DXILOpLowering.cpp b/llvm/lib/Target/DirectX/DXILOpLowering.cpp
index 0c0830cc92aa7..381cd0c463a0d 100644
--- a/llvm/lib/Target/DirectX/DXILOpLowering.cpp
+++ b/llvm/lib/Target/DirectX/DXILOpLowering.cpp
@@ -855,7 +855,7 @@ class OpLowerer {
 
       auto ZeroOrUndef = [&](Type *Ty) {
         return MMDI.ValidatorVersion < VersionTuple(1, 6)
-                   ? Constant::getNullValue(Ty)
+                   ? Constant::getNullValue(Ty, &M.getDataLayout())
                    : UndefValue::get(Ty);
       };
 
diff --git a/llvm/lib/Target/Hexagon/HexagonVectorCombine.cpp b/llvm/lib/Target/Hexagon/HexagonVectorCombine.cpp
index 1bb135a9e5c87..fe8969858c5fb 100644
--- a/llvm/lib/Target/Hexagon/HexagonVectorCombine.cpp
+++ b/llvm/lib/Target/Hexagon/HexagonVectorCombine.cpp
@@ -1412,7 +1412,7 @@ auto AlignVectors::realignStoreGroup(IRBuilderBase &Builder,
     ByteSpan VSection =
         VSpan.section(Index * ScLen, ScLen).shift(-Index * ScLen);
     Value *Undef = UndefValue::get(SecTy);
-    Value *Zero = Constant::getNullValue(SecTy);
+    Value *Zero = Constant::getNullValue(SecTy, &DL);
     Value *AccumV = Undef;
     Value *AccumM = Zero;
     for (ByteSpan::Block &S : VSection) {
@@ -2984,7 +2984,7 @@ auto HvxIdioms::processFxpMulChopped(IRBuilderBase &Builder, Instruction &In,
 
   // Add the optional rounding to the proper word.
   if (Op.RoundAt.has_value()) {
-    Value *Zero = Constant::getNullValue(WordX[0]->getType());
+    Value *Zero = Constant::getNullValue(WordX[0]->getType(), &DL);
     SmallVector<Value *> RoundV(WordP.size(), Zero);
     RoundV[*Op.RoundAt / 32] =
         ConstantInt::get(HvxWordTy, 1ull << (*Op.RoundAt % 32));
@@ -3064,7 +3064,7 @@ auto HvxIdioms::createAddCarry(IRBuilderBase &Builder, Value *X, Value *Y,
     } else {
       AddCarry = HVC.HST.getIntrinsicId(Hexagon::V6_vaddcarry);
       if (CarryIn == nullptr)
-        CarryIn = Constant::getNullValue(HVC.getBoolTy(HVC.length(VecTy)));
+        CarryIn = Constant::getNullValue(HVC.getBoolTy(HVC.length(VecTy)), &DL);
       Args.push_back(CarryIn);
     }
     Value *Ret = HVC.createHvxIntrinsic(Builder, AddCarry,
@@ -3212,7 +3212,7 @@ auto HvxIdioms::createMulLong(IRBuilderBase &Builder, ArrayRef<Value *> WordX,
     }
   }
 
-  Value *Zero = Constant::getNullValue(WordX[0]->getType());
+  Value *Zero = Constant::getNullValue(WordX[0]->getType(), &DL);
 
   auto pop_back_or_zero = [Zero](auto &Vector) -> Value * {
     if (Vector.empty())
diff --git a/llvm/lib/Target/NVPTX/NVPTXCtorDtorLowering.cpp b/llvm/lib/Target/NVPTX/NVPTXCtorDtorLowering.cpp
index 29ec718ea381c..6c31844c76ecc 100644
--- a/llvm/lib/Target/NVPTX/NVPTXCtorDtorLowering.cpp
+++ b/llvm/lib/Target/NVPTX/NVPTXCtorDtorLowering.cpp
@@ -108,7 +108,7 @@ static void createInitOrFiniCalls(Function &F, bool IsCtor) {
         auto *GV = new GlobalVariable(
             M, PointerType::get(C, 0),
             /*isConstant=*/false, GlobalValue::WeakAnyLinkage,
-            Constant::getNullValue(PointerType::get(C, 0)),
+            Constant::getNullValue(PointerType::get(C, 0), &M.getDataLayout()),
             IsCtor ? "__init_array_start" : "__fini_array_start",
             /*InsertBefore=*/nullptr, GlobalVariable::NotThreadLocal,
             /*AddressSpace=*/llvm::ADDRESS_SPACE_GLOBAL);
@@ -121,7 +121,7 @@ static void createInitOrFiniCalls(Function &F, bool IsCtor) {
         auto *GV = new GlobalVariable(
             M, PointerType::get(C, 0),
             /*isConstant=*/false, GlobalValue::WeakAnyLinkage,
-            Constant::getNullValue(PointerType::get(C, 0)),
+            Constant::getNullValue(PointerType::get(C, 0), &M.getDataLayout()),
             IsCtor ? "__init_array_end" : "__fini_array_end",
             /*InsertBefore=*/nullptr, GlobalVariable::NotThreadLocal,
             /*AddressSpace=*/llvm::ADDRESS_SPACE_GLOBAL);
diff --git a/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp b/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
index f5554be155eac..1dee3c8a16203 100644
--- a/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
+++ b/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
@@ -3600,7 +3600,8 @@ SDValue NVPTXTargetLowering::LowerVAARG(SDValue Op, SelectionDAG &DAG) const {
                       MachinePointerInfo(V));
 
   const Value *SrcV = Constant::getNullValue(
-      PointerType::get(*DAG.getContext(), ADDRESS_SPACE_LOCAL));
+      PointerType::get(*DAG.getContext(), ADDRESS_SPACE_LOCAL),
+      &DAG.getDataLayout());
 
   // Load the actual argument out of the pointer VAList
   return DAG.getLoad(VT, DL, Tmp1, VAList, MachinePointerInfo(SrcV));
diff --git a/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp b/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp
index 1c8774c59f065..b7b2a672a90bc 100644
--- a/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp
@@ -1616,7 +1616,8 @@ Instruction *SPIRVEmitIntrinsics::visitSwitchInst(SwitchInst &I) {
   // it will be removed after IR translation pass
   B.SetInsertPoint(ParentBB);
   IndirectBrInst *BrI = B.CreateIndirectBr(
-      Constant::getNullValue(PointerType::getUnqual(ParentBB->getContext())),
+      Constant::getNullValue(PointerType::getUnqual(ParentBB->getContext()),
+                             &I.getModule()->getDataLayout()),
       BBCases.size());
   for (BasicBlock *BBCase : BBCases)
     BrI->addDestination(BBCase);
diff --git a/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp b/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
index 033b5f455b6b6..cca10305bb5bc 100644
--- a/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
@@ -1772,9 +1772,10 @@ SPIRVInstructionSelector::getOrCreateMemSetGlobal(MachineInstr &I) const {
   Function &CurFunction = GR.CurMF->getFunction();
   Type *LLVMArrTy =
       ArrayType::get(IntegerType::get(CurFunction.getContext(), 8), Num);
-  GlobalVariable *GV = new GlobalVariable(*CurFunction.getParent(), LLVMArrTy,
-                                          true, GlobalValue::InternalLinkage,
-                                          Constant::getNullValue(LLVMArrTy));
+  GlobalVariable *GV = new GlobalVariable(
+      *CurFunction.getParent(), LLVMArrTy, true, GlobalValue::InternalLinkage,
+      Constant::getNullValue(LLVMArrTy,
+                             &CurFunction.getParent()->getDataLayout()));
 
   Type *ValTy = Type::getInt8Ty(I.getMF()->getFunction().getContext());
   Type *ArrTy = ArrayType::get(ValTy, Num);
diff --git a/llvm/lib/Target/SPIRV/SPIRVPrepareFunctions.cpp b/llvm/lib/Target/SPIRV/SPIRVPrepareFunctions.cpp
index 54f8b58114f7f..196ba5f901384 100644
--- a/llvm/lib/Target/SPIRV/SPIRVPrepareFunctions.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVPrepareFunctions.cpp
@@ -517,7 +517,8 @@ addFunctionTypeMutation(NamedMDNode *NMD,
   transform(ChangedTys, std::back_inserter(MDArgs), [=, &Ctx](auto &&CTy) {
     return MDNode::get(
         Ctx, {ConstantAsMetadata::get(ConstantInt::get(I32Ty, CTy.first, true)),
-              ValueAsMetadata::get(Constant::getNullValue(CTy.second))});
+              ValueAsMetadata::get(Constant::getNullValue(
+                  CTy.second, &NMD->getParent()->getDataLayout()))});
   });
   NMD->addOperand(MDNode::get(Ctx, MDArgs));
 }
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp
index 97f2ed0a828ba..3ed50bcad2fc5 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp
@@ -114,13 +114,15 @@ static void convertImplicitDefToConstZero(MachineInstr *MI,
     MI->addOperand(MachineOperand::CreateImm(0));
   } else if (RegClass == &WebAssembly::F32RegClass) {
     MI->setDesc(TII->get(WebAssembly::CONST_F32));
-    auto *Val = cast<ConstantFP>(Constant::getNullValue(
-        Type::getFloatTy(MF.getFunction().getContext())));
+    auto *Val = cast<ConstantFP>(
+        Constant::getNullValue(Type::getFloatTy(MF.getFunction().getContext()),
+                               &MF.getFunction().getParent()->getDataLayout()));
     MI->addOperand(MachineOperand::CreateFPImm(Val));
   } else if (RegClass == &WebAssembly::F64RegClass) {
     MI->setDesc(TII->get(WebAssembly::CONST_F64));
-    auto *Val = cast<ConstantFP>(Constant::getNullValue(
-        Type::getDoubleTy(MF.getFunction().getContext())));
+    auto *Val = cast<ConstantFP>(
+        Constant::getNullValue(Type::getDoubleTy(MF.getFunction().getContext()),
+                               &MF.getFunction().getParent()->getDataLayout()));
     MI->addOperand(MachineOperand::CreateFPImm(Val));
   } else if (RegClass == &WebAssembly::V128RegClass) {
     MI->setDesc(TII->get(WebAssembly::CONST_V128_I64x2));
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyTargetTransformInfo.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyTargetTransformInfo.cpp
index f058d734bcb87..da93eb9e38ca4 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyTargetTransformInfo.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyTargetTransformInfo.cpp
@@ -582,7 +582,9 @@ static Value *simplifyWasmSwizzle(const IntrinsicInst &II,
 
   auto *V1 = II.getArgOperand(0);
   auto *V2 =
-      AnyOutOfBounds ? Constant::getNullValue(VecTy) : PoisonValue::get(VecTy);
+      AnyOutOfBounds
+          ? Constant::getNullValue(VecTy, &II.getModule()->getDataLayout())
+          : PoisonValue::get(VecTy);
 
   return Builder.CreateShuffleVector(V1, V2, ArrayRef(Indexes, NumElts));
 }
diff --git a/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp b/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp
index 797fabde3f25c..4163d66c29e3c 100644
--- a/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp
+++ b/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp
@@ -1424,7 +1424,7 @@ static bool foldMemChr(CallInst *Call, DomTreeUpdater *DTU,
 
   PHINode *PHI =
       PHINode::Create(Call->getType(), 2, Call->getName(), BBNext->begin());
-  PHI->addIncoming(Constant::getNullValue(Call->getType()), BB);
+  PHI->addIncoming(Constant::getNullValue(Call->getType(), &DL), BB);
   PHI->addIncoming(FirstOccursLocation, BBSuccess);
 
   Call->replaceAllUsesWith(PHI);
diff --git a/llvm/lib/Transforms/Coroutines/CoroFrame.cpp b/llvm/lib/Transforms/Coroutines/CoroFrame.cpp
index 2f2ef7f9eee2c..b85f0c20dcff9 100644
--- a/llvm/lib/Transforms/Coroutines/CoroFrame.cpp
+++ b/llvm/lib/Transforms/Coroutines/CoroFrame.cpp
@@ -1771,7 +1771,7 @@ static void eliminateSwiftErrorArgument(Function &F, Argument &Arg,
   Arg.replaceAllUsesWith(Alloca);
 
   // Set an initial value in the alloca.  swifterror is always null on entry.
-  auto InitialValue = Constant::getNullValue(ValueTy);
+  auto InitialValue = Constant::getNullValue(ValueTy, &F.getDataLayout());
   Builder.CreateStore(InitialValue, Alloca);
 
   // Find all the suspends in the function and save and restore around them.
diff --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
index 42f08df47da38..8a67d5304271b 100644
--- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp
+++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
@@ -2427,7 +2427,8 @@ static bool OptimizeEmptyGlobalAtExitDtors(Function *CXAAtExitFn, bool isCXX) {
       continue;
 
     // Just remove the call.
-    CI->replaceAllUsesWith(Constant::getNullValue(CI->getType()));
+    CI->replaceAllUsesWith(Constant::getNullValue(
+        CI->getType(), &CI->getModule()->getDataLayout()));
     CI->eraseFromParent();
 
     if (isCXX)
diff --git a/llvm/lib/Transforms/IPO/LowerTypeTests.cpp b/llvm/lib/Transforms/IPO/LowerTypeTests.cpp
index 4c859511cc286..0c47a959e111a 100644
--- a/llvm/lib/Transforms/IPO/LowerTypeTests.cpp
+++ b/llvm/lib/Transforms/IPO/LowerTypeTests.cpp
@@ -1425,7 +1425,8 @@ void LowerTypeTestsModule::moveInitializerToModuleConstructor(
   IRBuilder<> IRB(WeakInitializerFn->getEntryBlock().getTerminator());
   GV->setConstant(false);
   IRB.CreateAlignedStore(GV->getInitializer(), GV, GV->getAlign());
-  GV->setInitializer(Constant::getNullValue(GV->getValueType()));
+  GV->setInitializer(
+      Constant::getNullValue(GV->getValueType(), &M.getDataLayout()));
 }
 
 void LowerTypeTestsModule::findGlobalVariableUsersOf(
@@ -1468,10 +1469,11 @@ void LowerTypeTestsModule::replaceWeakDeclarationWithJumpTablePtr(
     if (PN)
       InsertPt = PN->getIncomingBlock(U)->getTerminator();
     IRBuilder Builder(InsertPt);
-    Value *ICmp = Builder.CreateICmp(CmpInst::ICMP_NE, F,
-                                     Constant::getNullValue(F->getType()));
-    Value *Select = Builder.CreateSelect(ICmp, JT,
-                                         Constant::getNullValue(F->getType()));
+    Value *ICmp = Builder.CreateICmp(
+        CmpInst::ICMP_NE, F,
+        Constant::getNullValue(F->getType(), &M.getDataLayout()));
+    Value *Select = Builder.CreateSelect(
+        ICmp, JT, Constant::getNullValue(F->getType(), &M.getDataLayout()));
 
     if (auto *SI = dyn_cast<SelectInst>(Select))
       setExplicitlyUnknownBranchWeightsIfProfiled(*SI, DEBUG_TYPE);
diff --git a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
index 9c168c9d31b25..6c3e21205c807 100644
--- a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
+++ b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
@@ -4539,8 +4539,8 @@ struct AAKernelInfoFunction : AAKernelInfo {
 
     Instruction *IsDone =
         ICmpInst::Create(ICmpInst::ICmp, llvm::CmpInst::ICMP_EQ, WorkFn,
-                         Constant::getNullValue(VoidPtrTy), "worker.is_done",
-                         StateMachineBeginBB);
+                         Constant::getNullValue(VoidPtrTy, &DL),
+                         "worker.is_done", StateMachineBeginBB);
     IsDone->setDebugLoc(DLoc);
     BranchInst::Create(StateMachineFinishedBB, StateMachineIsActiveCheckBB,
                        IsDone, StateMachineBeginBB)
@@ -4552,7 +4552,7 @@ struct AAKernelInfoFunction : AAKernelInfo {
         ->setDebugLoc(DLoc);
 
     Value *ZeroArg =
-        Constant::getNullValue(ParallelRegionFnTy->getParamType(0));
+        Constant::getNullValue(ParallelRegionFnTy->getParamType(0), &DL);
 
     const unsigned int WrapperFunctionArgNo = 6;
 
diff --git a/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp b/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
index 7a6d9a14dc917..cd4e2fd41bb67 100644
--- a/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
+++ b/llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
@@ -1652,8 +1652,8 @@ bool DevirtModule::tryEvaluateFunctionsWithArgs(
 
     Evaluator Eval(M.getDataLayout(), nullptr);
     SmallVector<Constant *, 2> EvalArgs;
-    EvalArgs.push_back(
-        Constant::getNullValue(Fn->getFunctionType()->getParamType(0)));
+    EvalArgs.push_back(Constant::getNullValue(
+        Fn->getFunctionType()->getParamType(0), &M.getDataLayout()));
     for (unsigned I = 0; I != Args.size(); ++I) {
       auto *ArgTy =
           dyn_cast<IntegerType>(Fn->getFunctionType()->getParamType(I + 1));
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
index 8eeeccbc86523..3cd3e0baad204 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
@@ -1660,7 +1660,7 @@ Instruction *InstCombinerImpl::visitAdd(BinaryOperator &I) {
   // zext(A) + sext(A) --> 0 if A is i1
   if (match(&I, m_c_BinOp(m_ZExt(m_Value(A)), m_SExt(m_Deferred(A)))) &&
       A->getType()->isIntOrIntVectorTy(1))
-    return replaceInstUsesWith(I, Constant::getNullValue(I.getType()));
+    return replaceInstUsesWith(I, Constant::getNullValue(I.getType(), &DL));
 
   // sext(A < B) + zext(A > B) => ucmp/scmp(A, B)
   CmpPredicate LTPred, GTPred;
@@ -2824,7 +2824,7 @@ Instruction *InstCombinerImpl::visitSub(BinaryOperator &I) {
     Value *IsNeg = Builder.CreateIsNeg(A);
     // Copy the nsw flags from the sub to the negate.
     Value *NegA = I.hasNoUnsignedWrap()
-                      ? Constant::getNullValue(A->getType())
+                      ? Constant::getNullValue(A->getType(), &DL)
                       : Builder.CreateNeg(A, "", I.hasNoSignedWrap());
     return SelectInst::Create(IsNeg, NegA, A);
   }
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
index 073f094639fa0..efd8cfc9ed664 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
@@ -1829,7 +1829,7 @@ Instruction *InstCombinerImpl::foldCastedBitwiseLogic(BinaryOperator &I) {
       return nullptr;
 
     auto *ICmpL =
-        Builder.CreateICmpSLT(A, Constant::getNullValue(A->getType()));
+        Builder.CreateICmpSLT(A, Constant::getNullValue(A->getType(), &DL));
     auto *ICmpR = cast<ZExtInst>(Op1)->getOperand(0);
     auto *BitwiseOp = Builder.CreateBinOp(LogicOpc, ICmpL, ICmpR);
 
@@ -2816,31 +2816,33 @@ Instruction *InstCombinerImpl::visitAnd(BinaryOperator &I) {
   Value *A, *B;
   if (match(&I, m_c_And(m_SExt(m_Value(A)), m_Value(B))) &&
       A->getType()->isIntOrIntVectorTy(1))
-    return createSelectInstWithUnknownProfile(A, B, Constant::getNullValue(Ty));
+    return createSelectInstWithUnknownProfile(A, B,
+                                              Constant::getNullValue(Ty, &DL));
 
   // Similarly, a 'not' of the bool translates to a swap of the select arms:
   // ~sext(A) & B / B & ~sext(A) --> A ? 0 : B
   if (match(&I, m_c_And(m_Not(m_SExt(m_Value(A))), m_Value(B))) &&
       A->getType()->isIntOrIntVectorTy(1))
-    return createSelectInstWithUnknownProfile(A, Constant::getNullValue(Ty), B);
+    return createSelectInstWithUnknownProfile(
+        A, Constant::getNullValue(Ty, &DL), B);
 
   // and(zext(A), B) -> A ? (B & 1) : 0
   if (match(&I, m_c_And(m_OneUse(m_ZExt(m_Value(A))), m_Value(B))) &&
       A->getType()->isIntOrIntVectorTy(1))
     return createSelectInstWithUnknownProfile(
         A, Builder.CreateAnd(B, ConstantInt::get(Ty, 1)),
-        Constant::getNullValue(Ty));
+        Constant::getNullValue(Ty, &DL));
 
   // (-1 + A) & B --> A ? 0 : B where A is 0/1.
   if (match(&I, m_c_And(m_OneUse(m_Add(m_ZExtOrSelf(m_Value(A)), m_AllOnes())),
                         m_Value(B)))) {
     if (A->getType()->isIntOrIntVectorTy(1))
-      return createSelectInstWithUnknownProfile(A, Constant::getNullValue(Ty),
-                                                B);
+      return createSelectInstWithUnknownProfile(
+          A, Constant::getNullValue(Ty, &DL), B);
     if (computeKnownBits(A, &I).countMaxActiveBits() <= 1) {
       return createSelectInstWithUnknownProfile(
-          Builder.CreateICmpEQ(A, Constant::getNullValue(A->getType())), B,
-          Constant::getNullValue(Ty));
+          Builder.CreateICmpEQ(A, Constant::getNullValue(A->getType(), &DL)), B,
+          Constant::getNullValue(Ty, &DL));
     }
   }
 
@@ -3463,7 +3465,7 @@ Value *InstCombinerImpl::foldAndOrOfICmps(ICmpInst *LHS, ICmpInst *RHS,
       (!IsLogical || isGuaranteedNotToBePoison(RHS0))) {
     Value *NewOr = Builder.CreateOr(LHS0, RHS0);
     return Builder.CreateICmp(PredL, NewOr,
-                              Constant::getNullValue(NewOr->getType()));
+                              Constant::getNullValue(NewOr->getType(), &DL));
   }
 
   // (icmp ne A, -1) | (icmp ne B, -1) --> (icmp ne (A&B), -1)
@@ -3763,7 +3765,7 @@ static Instruction *foldIntegerPackFromVector(Instruction &I,
   }
 
   Value *MaskedVec = Builder.CreateShuffleVector(
-      LhsVec, Constant::getNullValue(LhsVec->getType()), ShuffleMask,
+      LhsVec, Constant::getNullValue(LhsVec->getType(), &DL), ShuffleMask,
       I.getName() + ".v");
   return CastInst::Create(Instruction::BitCast, MaskedVec, I.getType());
 }
@@ -4634,11 +4636,11 @@ Instruction *InstCombinerImpl::visitOr(BinaryOperator &I) {
     return Res;
 
   if (Value *V =
-          simplifyAndOrWithOpReplaced(Op0, Op1, Constant::getNullValue(Ty),
+          simplifyAndOrWithOpReplaced(Op0, Op1, Constant::getNullValue(Ty, &DL),
                                       /*SimplifyOnly*/ false, *this))
     return BinaryOperator::CreateOr(V, Op1);
   if (Value *V =
-          simplifyAndOrWithOpReplaced(Op1, Op0, Constant::getNullValue(Ty),
+          simplifyAndOrWithOpReplaced(Op1, Op0, Constant::getNullValue(Ty, &DL),
                                       /*SimplifyOnly*/ false, *this))
     return BinaryOperator::CreateOr(Op0, V);
 
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index 93161d2d1145e..6076656a9aa84 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -2070,7 +2070,7 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
     if (match(I1, m_One())) {
       assert(II->getType()->getScalarSizeInBits() != 1 &&
              "Expected simplify of umin with max constant");
-      Value *Zero = Constant::getNullValue(I0->getType());
+      Value *Zero = Constant::getNullValue(I0->getType(), &DL);
       Value *Cmp = Builder.CreateICmpNE(I0, Zero);
       return CastInst::Create(Instruction::ZExt, Cmp, II->getType());
     }
@@ -4221,7 +4221,8 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
     if (match(II->getArgOperand(0), m_ExtractValue<0>(m_Value(X)))) {
       if (match(X, m_Intrinsic<Intrinsic::frexp>(m_Value()))) {
         X = Builder.CreateInsertValue(
-            X, Constant::getNullValue(II->getType()->getStructElementType(1)),
+            X,
+            Constant::getNullValue(II->getType()->getStructElementType(1), &DL),
             1);
         return replaceInstUsesWith(*II, X);
       }
@@ -4236,7 +4237,7 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
       return replaceInstUsesWith(
           *II, Builder.CreateIntrinsic(
                    II->getType(), Intrinsic::get_active_lane_mask,
-                   {Constant::getNullValue(OpTy),
+                   {Constant::getNullValue(OpTy, &DL),
                     ConstantInt::get(OpTy, Op1->usub_sat(*Op0))}));
     }
     break;
@@ -4756,7 +4757,7 @@ Instruction *InstCombinerImpl::visitCallBase(CallBase &Call) {
       // CFG, just change the callee to a null pointer.
       cast<CallBase>(OldCall)->setCalledFunction(
           CalleeF->getFunctionType(),
-          Constant::getNullValue(CalleeF->getType()));
+          Constant::getNullValue(CalleeF->getType(), &DL));
       return nullptr;
     }
   }
@@ -5127,7 +5128,7 @@ bool InstCombinerImpl::transformConstExprCastCall(CallBase &Call) {
   // If the function takes more arguments than the call was taking, add them
   // now.
   for (unsigned i = NumCommonArgs; i != FT->getNumParams(); ++i) {
-    Args.push_back(Constant::getNullValue(FT->getParamType(i)));
+    Args.push_back(Constant::getNullValue(FT->getParamType(i), &DL));
     ArgAttrs.push_back(AttributeSet());
   }
 
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
index 2f3c9c6a083bd..a1a7932d516eb 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
@@ -1028,7 +1028,7 @@ Instruction *InstCombinerImpl::visitTrunc(TruncInst &Trunc) {
     return &Trunc;
 
   if (DestWidth == 1) {
-    Value *Zero = Constant::getNullValue(SrcTy);
+    Value *Zero = Constant::getNullValue(SrcTy, &DL);
 
     Value *X;
     const APInt *C1;
@@ -1467,7 +1467,8 @@ Instruction *InstCombinerImpl::visitZExt(ZExtInst &Zext) {
 
   // zext nneg bool x -> 0
   if (SrcTy->isIntOrIntVectorTy(1) && Zext.hasNonNeg())
-    return replaceInstUsesWith(Zext, Constant::getNullValue(Zext.getType()));
+    return replaceInstUsesWith(Zext,
+                               Constant::getNullValue(Zext.getType(), &DL));
 
   // Try to extend the entire expression tree to the wide destination type.
   unsigned BitsToClear;
@@ -2415,7 +2416,7 @@ Value *InstCombinerImpl::foldPtrToIntOrAddrOfGEP(Type *IntTy, Value *Ptr) {
       Res->getType() == IntTy && IntTy == IdxTy) {
     // pass
   } else if (isa<ConstantPointerNull>(Ptr)) {
-    Res = Constant::getNullValue(IdxTy);
+    Res = Constant::getNullValue(IdxTy, &DL);
   } else {
     return nullptr;
   }
@@ -3145,9 +3146,9 @@ Instruction *InstCombinerImpl::visitBitCast(BitCastInst &CI) {
       // If our destination is not a vector, then make this a straight
       // scalar-scalar cast.
       if (!DestTy->isVectorTy()) {
-        Value *Elem =
-          Builder.CreateExtractElement(Src,
-                     Constant::getNullValue(Type::getInt32Ty(CI.getContext())));
+        Value *Elem = Builder.CreateExtractElement(
+            Src,
+            Constant::getNullValue(Type::getInt32Ty(CI.getContext()), &DL));
         return CastInst::Create(Instruction::BitCast, Elem, DestTy);
       }
 
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index fbc728bbb9ee3..eee27f13453e2 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -688,7 +688,7 @@ Instruction *InstCombinerImpl::foldGEPICmp(GEPOperator *GEPLHS, Value *RHS,
     Value *Offset =
         EmitGEPOffsets(Base.LHSGEPs, Base.LHSNW, IdxTy, /*RewriteGEPs=*/true);
     return NewICmp(Base.LHSNW, Offset,
-                   Constant::getNullValue(Offset->getType()));
+                   Constant::getNullValue(Offset->getType(), &DL));
   }
 
   if (GEPLHS->isInBounds() && ICmpInst::isEquality(Cond) &&
@@ -1278,7 +1278,7 @@ Instruction *InstCombinerImpl::foldICmpWithZero(ICmpInst &Cmp) {
   if (ICmpInst::isEquality(Pred))
     if (Value *Stripped = stripNullTest(Cmp.getOperand(0)))
       return new ICmpInst(Pred, Stripped,
-                          Constant::getNullValue(Stripped->getType()));
+                          Constant::getNullValue(Stripped->getType(), &DL));
 
   return nullptr;
 }
@@ -1307,7 +1307,7 @@ Instruction *InstCombinerImpl::foldIsMultipleOfAPowerOfTwo(ICmpInst &Cmp) {
 
   // Create new icmp eq (num & mask), 0
   auto *NewAnd = Builder.CreateAnd(Num, *Mask);
-  auto *Zero = Constant::getNullValue(Num->getType());
+  auto *Zero = Constant::getNullValue(Num->getType(), &DL);
 
   return new ICmpInst(Pred, NewAnd, Zero);
 }
@@ -1814,7 +1814,7 @@ Instruction *InstCombinerImpl::foldICmpAndConstConst(ICmpInst &Cmp,
     // Restrict this fold to single-use 'and' (PR10267).
     // Replace (and X, (1 << size(X)-1) != 0) with X s< 0
     if (C2->isSignMask()) {
-      Constant *Zero = Constant::getNullValue(X->getType());
+      Constant *Zero = Constant::getNullValue(X->getType(), &DL);
       auto NewPred = isICMP_NE ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_SGE;
       return new ICmpInst(NewPred, X, Zero);
     }
@@ -1998,7 +1998,8 @@ Instruction *InstCombinerImpl::foldICmpAndConstant(ICmpInst &Cmp,
       match(And, m_OneUse(m_c_And(m_OneUse(m_Shl(m_AllOnes(), m_Value(X))),
                                   m_Value(Y))))) {
     Value *LShr = Builder.CreateLShr(Y, X);
-    return new ICmpInst(Pred, LShr, Constant::getNullValue(LShr->getType()));
+    return new ICmpInst(Pred, LShr,
+                        Constant::getNullValue(LShr->getType(), &DL));
   }
 
   // (icmp eq/ne (and (add A, Addend), Msk), C)
@@ -2436,7 +2437,7 @@ Instruction *InstCombinerImpl::foldICmpShlConstant(ICmpInst &Cmp,
         APInt::getOneBitSet(TypeBits, TypeBits - ShiftAmt->getZExtValue() - 1));
     Value *And = Builder.CreateAnd(X, Mask, Shl->getName() + ".mask");
     return new ICmpInst(TrueIfSigned ? ICmpInst::ICMP_NE : ICmpInst::ICMP_EQ,
-                        And, Constant::getNullValue(ShType));
+                        And, Constant::getNullValue(ShType, &DL));
   }
 
   // Simplify 'shl' inequality test into 'and' equality test.
@@ -2447,7 +2448,7 @@ Instruction *InstCombinerImpl::foldICmpShlConstant(ICmpInst &Cmp,
       Value *And = Builder.CreateAnd(X, (~C).lshr(ShiftAmt->getZExtValue()));
       return new ICmpInst(Pred == ICmpInst::ICMP_ULE ? ICmpInst::ICMP_EQ
                                                      : ICmpInst::ICMP_NE,
-                          And, Constant::getNullValue(ShType));
+                          And, Constant::getNullValue(ShType, &DL));
     }
     // (X l<< C2) u</u>= C1 iff C1 is power of two -> X & (-C1 l>> C2) ==/!= 0
     if (C.isPowerOf2() &&
@@ -2456,7 +2457,7 @@ Instruction *InstCombinerImpl::foldICmpShlConstant(ICmpInst &Cmp,
           Builder.CreateAnd(X, (~(C - 1)).lshr(ShiftAmt->getZExtValue()));
       return new ICmpInst(Pred == ICmpInst::ICMP_ULT ? ICmpInst::ICMP_EQ
                                                      : ICmpInst::ICMP_NE,
-                          And, Constant::getNullValue(ShType));
+                          And, Constant::getNullValue(ShType, &DL));
     }
   }
 
@@ -3632,7 +3633,7 @@ Instruction *InstCombinerImpl::foldICmpBinOpEqualityWithConstant(
       if (match(BOp1, m_APInt(BOC)) && BOC->sgt(1) && BOC->isPowerOf2()) {
         Value *NewRem = Builder.CreateURem(BOp0, BOp1, BO->getName());
         return new ICmpInst(Pred, NewRem,
-                            Constant::getNullValue(BO->getType()));
+                            Constant::getNullValue(BO->getType(), &DL));
       }
     }
     break;
@@ -3654,7 +3655,8 @@ Instruction *InstCombinerImpl::foldICmpBinOpEqualityWithConstant(
         // (add nuw A, B) != 0 -> (or A, B) != 0
         if (match(BO, m_NUWAdd(m_Value(), m_Value()))) {
           Value *Or = Builder.CreateOr(BOp0, BOp1);
-          return new ICmpInst(Pred, Or, Constant::getNullValue(BO->getType()));
+          return new ICmpInst(Pred, Or,
+                              Constant::getNullValue(BO->getType(), &DL));
         }
         Value *Neg = Builder.CreateNeg(BOp1);
         Neg->takeName(BO);
@@ -3701,7 +3703,7 @@ Instruction *InstCombinerImpl::foldICmpBinOpEqualityWithConstant(
               ? (match(TV, m_Zero()) && isKnownNonZero(FV, Q))
               : (match(FV, m_Zero()) && isKnownNonZero(TV, Q))) {
         Value *Cmp = Builder.CreateICmp(
-            Pred, Other, Constant::getNullValue(Other->getType()));
+            Pred, Other, Constant::getNullValue(Other->getType(), &DL));
         return BinaryOperator::Create(
             Pred == ICmpInst::ICMP_EQ ? Instruction::And : Instruction::Or, Cmp,
             Cond);
@@ -3724,7 +3726,7 @@ Instruction *InstCombinerImpl::foldICmpBinOpEqualityWithConstant(
                : (match(TV, m_Zero()) && isKnownNonZero(FV, Q)))) {
         Value *NotCond = Builder.CreateNot(Cond);
         Value *Cmp = Builder.CreateICmp(
-            Pred, Other, Constant::getNullValue(Other->getType()));
+            Pred, Other, Constant::getNullValue(Other->getType(), &DL));
         return BinaryOperator::Create(
             Pred == ICmpInst::ICMP_EQ ? Instruction::And : Instruction::Or, Cmp,
             NotCond);
@@ -3741,7 +3743,8 @@ Instruction *InstCombinerImpl::foldICmpBinOpEqualityWithConstant(
       //    if Y * C never-overflow && OneUse:
       //      -> Y * C eq/ne X
       if (C.isZero())
-        return new ICmpInst(Pred, BOp0, Constant::getNullValue(BO->getType()));
+        return new ICmpInst(Pred, BOp0,
+                            Constant::getNullValue(BO->getType(), &DL));
       else if (C.isOne())
         return new ICmpInst(Pred, BOp0, BOp1);
       else if (BO->hasOneUse()) {
@@ -3797,7 +3800,7 @@ static Instruction *foldCtpopPow2Test(ICmpInst &I, IntrinsicInst *CtpopLhs,
           (Pred == ICmpInst::ICMP_EQ || Pred == ICmpInst::ICMP_ULT)
               ? ICmpInst::ICMP_EQ
               : ICmpInst::ICMP_NE,
-          And, Constant::getNullValue(Op->getType()));
+          And, Constant::getNullValue(Op->getType(), &Q.DL));
     }
   }
 
@@ -3859,7 +3862,7 @@ Instruction *InstCombinerImpl::foldICmpEqIntrinsicWithConstant(
     bool IsZero = C.isZero();
     if (IsZero || C == BitWidth)
       return new ICmpInst(Pred, II->getArgOperand(0),
-                          IsZero ? Constant::getNullValue(Ty)
+                          IsZero ? Constant::getNullValue(Ty, &DL)
                                  : Constant::getAllOnesValue(Ty));
 
     break;
@@ -3885,7 +3888,7 @@ Instruction *InstCombinerImpl::foldICmpEqIntrinsicWithConstant(
     // umax(a, b) == 0  ->  (a | b) == 0
     if (C.isZero() && II->hasOneUse()) {
       Value *Or = Builder.CreateOr(II->getArgOperand(0), II->getArgOperand(1));
-      return new ICmpInst(Pred, Or, Constant::getNullValue(Ty));
+      return new ICmpInst(Pred, Or, Constant::getNullValue(Ty, &DL));
     }
     break;
   }
@@ -4350,7 +4353,7 @@ Instruction *InstCombinerImpl::foldICmpInstWithConstantNotInt(ICmpInst &I) {
         DL.getIntPtrType(RHSC->getType()) == LHSI->getOperand(0)->getType())
       return new ICmpInst(
           I.getPredicate(), LHSI->getOperand(0),
-          Constant::getNullValue(LHSI->getOperand(0)->getType()));
+          Constant::getNullValue(LHSI->getOperand(0)->getType(), &DL));
     break;
 
   case Instruction::Load:
@@ -4904,7 +4907,7 @@ foldShiftIntoShiftInAnotherHandOfAndInICmp(ICmpInst &I, const SimplifyQuery SQ,
                   : Builder.CreateShl(X, NewShAmt);
   Value *T1 = Builder.CreateAnd(T0, Y);
   return Builder.CreateICmp(I.getPredicate(), T1,
-                            Constant::getNullValue(WidestTy));
+                            Constant::getNullValue(WidestTy, &SQ.DL));
 }
 
 /// Fold
@@ -4994,8 +4997,9 @@ static Instruction *foldICmpXNegX(ICmpInst &I,
       Pred = ICmpInst::getSignedPredicate(Pred);
     // else for equality-comparisons just keep the predicate.
 
-    return ICmpInst::Create(Instruction::ICmp, Pred, X,
-                            Constant::getNullValue(X->getType()), I.getName());
+    return ICmpInst::Create(
+        Instruction::ICmp, Pred, X,
+        Constant::getNullValue(X->getType(), &I.getDataLayout()), I.getName());
   }
 
   // A value is not equal to its negation unless that value is 0 or
@@ -5007,7 +5011,7 @@ static Instruction *foldICmpXNegX(ICmpInst &I,
     Constant *MaxSignedVal =
         ConstantInt::get(Ty, APInt::getSignedMaxValue(BitWidth));
     Value *And = Builder.CreateAnd(X, MaxSignedVal);
-    Constant *Zero = Constant::getNullValue(Ty);
+    Constant *Zero = Constant::getNullValue(Ty, &I.getDataLayout());
     return CmpInst::Create(Instruction::ICmp, Pred, And, Zero);
   }
 
@@ -5047,7 +5051,7 @@ static Instruction *foldICmpAndXX(ICmpInst &I, const SimplifyQuery &Q,
     // icmp (X & Y) eq/ne Y --> (~X & Y) eq/ne 0 if X  is freely invertible.
     if (auto *NotA = IC.getFreelyInverted(A, A->hasOneUse(), &IC.Builder))
       return new ICmpInst(Pred, IC.Builder.CreateAnd(Op1, NotA),
-                          Constant::getNullValue(Op1->getType()));
+                          Constant::getNullValue(Op1->getType(), &Q.DL));
   }
 
   if (!ICmpInst::isSigned(Pred))
@@ -5065,13 +5069,13 @@ static Instruction *foldICmpAndXX(ICmpInst &I, const SimplifyQuery &Q,
     // (X & PosY) s<= X --> X s>= 0
     // (X & PosY) s> X --> X s< 0
     return new ICmpInst(ICmpInst::getSwappedPredicate(Pred), Op1,
-                        Constant::getNullValue(Op1->getType()));
+                        Constant::getNullValue(Op1->getType(), &Q.DL));
 
   if (isKnownNegative(Op1, IC.getSimplifyQuery().getWithInstruction(&I)))
     // (NegX & Y) s<= NegX --> Y s< 0
     // (NegX & Y) s> NegX --> Y s>= 0
     return new ICmpInst(ICmpInst::getFlippedStrictnessPredicate(Pred), A,
-                        Constant::getNullValue(A->getType()));
+                        Constant::getNullValue(A->getType(), &Q.DL));
 
   return nullptr;
 }
@@ -5102,7 +5106,7 @@ static Instruction *foldICmpOrXX(ICmpInst &I, const SimplifyQuery &Q,
     if (Value *NotOp1 = IC.getFreelyInverted(
             Op1, !isa<Constant>(Op1) && !Op1->hasNUsesOrMore(3), &IC.Builder))
       return new ICmpInst(Pred, IC.Builder.CreateAnd(A, NotOp1),
-                          Constant::getNullValue(Op1->getType()));
+                          Constant::getNullValue(Op1->getType(), &Q.DL));
     // icmp (X | Y) eq/ne Y --> (~X | Y) eq/ne -1 if X  is freely invertible.
     if (Value *NotA = IC.getFreelyInverted(A, A->hasOneUse(), &IC.Builder))
       return new ICmpInst(Pred, IC.Builder.CreateOr(Op1, NotA),
@@ -5148,7 +5152,7 @@ static Instruction *foldICmpXorXX(ICmpInst &I, const SimplifyQuery &Q,
       NewPred = ICmpInst::ICMP_SGE;
       break;
     }
-    Constant *Const = Constant::getNullValue(Op0->getType());
+    Constant *Const = Constant::getNullValue(Op0->getType(), &Q.DL);
     return new ICmpInst(NewPred, Op0, Const);
   }
 
@@ -5291,12 +5295,12 @@ Instruction *InstCombinerImpl::foldICmpBinOp(ICmpInst &I,
   // icmp (A+B), B -> icmp A, 0 for equalities or if there is no overflow.
   if ((A == Op1 || B == Op1) && NoOp0WrapProblem)
     return new ICmpInst(Pred, A == Op1 ? B : A,
-                        Constant::getNullValue(Op1->getType()));
+                        Constant::getNullValue(Op1->getType(), &DL));
 
   // icmp C, (C+D) -> icmp 0, D for equalities or if there is no overflow.
   // icmp D, (C+D) -> icmp 0, C for equalities or if there is no overflow.
   if ((C == Op0 || D == Op0) && NoOp1WrapProblem)
-    return new ICmpInst(Pred, Constant::getNullValue(Op0->getType()),
+    return new ICmpInst(Pred, Constant::getNullValue(Op0->getType(), &DL),
                         C == Op0 ? D : C);
 
   // icmp (A+B), (A+D) -> icmp B, D for equalities or if there is no overflow.
@@ -5439,10 +5443,10 @@ Instruction *InstCombinerImpl::foldICmpBinOp(ICmpInst &I,
 
   // icmp (A-B), A -> icmp 0, B for equalities or if there is no overflow.
   if (A == Op1 && NoOp0WrapProblem)
-    return new ICmpInst(Pred, Constant::getNullValue(Op1->getType()), B);
+    return new ICmpInst(Pred, Constant::getNullValue(Op1->getType(), &DL), B);
   // icmp C, (C-D) -> icmp D, 0 for equalities or if there is no overflow.
   if (C == Op0 && NoOp1WrapProblem)
-    return new ICmpInst(Pred, D, Constant::getNullValue(Op0->getType()));
+    return new ICmpInst(Pred, D, Constant::getNullValue(Op0->getType(), &DL));
 
   // Convert sub-with-unsigned-overflow comparisons into a comparison of args.
   // (A - B) u>/u<= A --> B u>/u<= A
@@ -5502,11 +5506,12 @@ Instruction *InstCombinerImpl::foldICmpBinOp(ICmpInst &I,
                                              SQ.getWithInstruction(&I));
           if (LessThan && match(LessThan, m_One()))
             return new ICmpInst(ICmpInst::getSwappedPredicate(Pred), Z,
-                                Constant::getNullValue(Z->getType()));
+                                Constant::getNullValue(Z->getType(), &DL));
           Value *GreaterThan = simplifyICmpInst(ICmpInst::ICMP_SGT, X, Y,
                                                 SQ.getWithInstruction(&I));
           if (GreaterThan && match(GreaterThan, m_One()))
-            return new ICmpInst(Pred, Z, Constant::getNullValue(Z->getType()));
+            return new ICmpInst(Pred, Z,
+                                Constant::getNullValue(Z->getType(), &DL));
         }
       } else {
         bool NonZero;
@@ -5514,7 +5519,8 @@ Instruction *InstCombinerImpl::foldICmpBinOp(ICmpInst &I,
           // If X != Y, fold (X *nw Z) eq/ne (Y *nw Z) -> Z eq/ne 0
           if (((Op0HasNSW && Op1HasNSW) || (Op0HasNUW && Op1HasNUW)) &&
               isKnownNonEqual(X, Y, SQ))
-            return new ICmpInst(Pred, Z, Constant::getNullValue(Z->getType()));
+            return new ICmpInst(Pred, Z,
+                                Constant::getNullValue(Z->getType(), &DL));
 
           KnownBits ZKnown = computeKnownBits(Z, &I);
           // if Z % 2 != 0
@@ -5562,7 +5568,7 @@ Instruction *InstCombinerImpl::foldICmpBinOp(ICmpInst &I,
     case ICmpInst::ICMP_SLT:
     case ICmpInst::ICMP_SLE:
       return new ICmpInst(ICmpInst::ICMP_SLT, SRem->getOperand(1),
-                          Constant::getNullValue(SRem->getType()));
+                          Constant::getNullValue(SRem->getType(), &DL));
     }
   }
 
@@ -5650,7 +5656,7 @@ Instruction *InstCombinerImpl::foldICmpBinOp(ICmpInst &I,
     auto BitwiseAnd = m_c_And(m_Value(), LSubOne);
 
     if (match(BO0, BitwiseAnd) && Pred == ICmpInst::ICMP_ULT) {
-      auto *Zero = Constant::getNullValue(BO0->getType());
+      auto *Zero = Constant::getNullValue(BO0->getType(), &DL);
       return new ICmpInst(ICmpInst::ICMP_NE, Op1, Zero);
     }
   }
@@ -5661,10 +5667,10 @@ Instruction *InstCombinerImpl::foldICmpBinOp(ICmpInst &I,
   if (!ICmpInst::isSigned(Pred)) {
     if (match(Op0, m_Shl(m_Specific(Op1), m_One())))
       return new ICmpInst(ICmpInst::getSignedPredicate(Pred), Op1,
-                          Constant::getNullValue(Op1->getType()));
+                          Constant::getNullValue(Op1->getType(), &DL));
     else if (match(Op1, m_Shl(m_Specific(Op0), m_One())))
       return new ICmpInst(ICmpInst::getSignedPredicate(Pred),
-                          Constant::getNullValue(Op0->getType()), Op0);
+                          Constant::getNullValue(Op0->getType(), &DL), Op0);
   }
 
   if (Value *V = foldMultiplicationOverflowCheck(I))
@@ -6084,7 +6090,8 @@ Instruction *InstCombinerImpl::foldICmpEquality(ICmpInst &I) {
   if (match(Op0, m_Xor(m_Value(A), m_Value(B)))) {
     if (A == Op1 || B == Op1) { // (A^B) == A  ->  B == 0
       Value *OtherVal = A == Op1 ? B : A;
-      return new ICmpInst(Pred, OtherVal, Constant::getNullValue(A->getType()));
+      return new ICmpInst(Pred, OtherVal,
+                          Constant::getNullValue(A->getType(), &DL));
     }
 
     if (match(Op1, m_Xor(m_Value(C), m_Value(D)))) {
@@ -6112,7 +6119,8 @@ Instruction *InstCombinerImpl::foldICmpEquality(ICmpInst &I) {
   if (match(Op1, m_Xor(m_Value(A), m_Value(B))) && (A == Op0 || B == Op0)) {
     // A == (A^B)  ->  B == 0
     Value *OtherVal = A == Op0 ? B : A;
-    return new ICmpInst(Pred, OtherVal, Constant::getNullValue(A->getType()));
+    return new ICmpInst(Pred, OtherVal,
+                        Constant::getNullValue(A->getType(), &DL));
   }
 
   // (X&Z) == (Y&Z) -> (X^Y) & Z == 0
@@ -6156,7 +6164,8 @@ Instruction *InstCombinerImpl::foldICmpEquality(ICmpInst &I) {
         // Build (X^Y) & Z
         Op1 = Builder.CreateXor(X, Y);
         Op1 = Builder.CreateAnd(Op1, Z);
-        return new ICmpInst(Pred, Op1, Constant::getNullValue(Op1->getType()));
+        return new ICmpInst(Pred, Op1,
+                            Constant::getNullValue(Op1->getType(), &DL));
       }
     }
   }
@@ -6170,7 +6179,8 @@ Instruction *InstCombinerImpl::foldICmpEquality(ICmpInst &I) {
         match(Op1, m_OneUse(m_Or(m_Value(Y), m_Specific(C))))) {
       Value *Xor = Builder.CreateXor(X, Y);
       Value *And = Builder.CreateAnd(Xor, ConstantExpr::getNot(C));
-      return new ICmpInst(Pred, And, Constant::getNullValue(And->getType()));
+      return new ICmpInst(Pred, And,
+                          Constant::getNullValue(And->getType(), &DL));
     }
   }
 
@@ -6215,7 +6225,8 @@ Instruction *InstCombinerImpl::foldICmpEquality(ICmpInst &I) {
       APInt AndVal = APInt::getLowBitsSet(TypeBits, TypeBits - ShAmt);
       Value *And =
           Builder.CreateAnd(Xor, Builder.getInt(AndVal), I.getName() + ".mask");
-      return new ICmpInst(Pred, And, Constant::getNullValue(Cst1->getType()));
+      return new ICmpInst(Pred, And,
+                          Constant::getNullValue(Cst1->getType(), &DL));
     }
   }
 
@@ -6394,7 +6405,7 @@ Instruction *InstCombinerImpl::foldICmpWithZextOrSext(ICmpInst &ICmp) {
       if (ICmp.isEquality() && X->getType()->isIntOrIntVectorTy(1) &&
           Y->getType()->isIntOrIntVectorTy(1))
         return new ICmpInst(ICmp.getPredicate(), Builder.CreateOr(X, Y),
-                            Constant::getNullValue(X->getType()));
+                            Constant::getNullValue(X->getType(), &DL));
 
       // If we have mismatched casts and zext has the nneg flag, we can
       //  treat the "zext nneg" as "sext". Otherwise, we cannot fold and quit.
@@ -6479,7 +6490,7 @@ Instruction *InstCombinerImpl::foldICmpWithZextOrSext(ICmpInst &ICmp) {
   // Is source op negative?
   // icmp ugt (sext X), C --> icmp slt X, 0
   assert(ICmp.getPredicate() == ICmpInst::ICMP_UGT && "ICmp should be folded!");
-  return new ICmpInst(CmpInst::ICMP_SLT, X, Constant::getNullValue(SrcTy));
+  return new ICmpInst(CmpInst::ICMP_SLT, X, Constant::getNullValue(SrcTy, &DL));
 }
 
 /// Handle icmp (cast x), (cast or constant).
@@ -7028,7 +7039,7 @@ Instruction *InstCombinerImpl::foldICmpUsingKnownBits(ICmpInst &I) {
         // exceeds the log2 of C.
         if (Op0Known.countMinTrailingZeros() >= CmpC->ceilLogBase2())
           return new ICmpInst(ICmpInst::ICMP_EQ, Op0,
-                              Constant::getNullValue(Op1->getType()));
+                              Constant::getNullValue(Op1->getType(), &DL));
       }
       break;
     }
@@ -7045,7 +7056,7 @@ Instruction *InstCombinerImpl::foldICmpUsingKnownBits(ICmpInst &I) {
         // exceeds the log2 of C.
         if (Op0Known.countMinTrailingZeros() >= CmpC->getActiveBits())
           return new ICmpInst(ICmpInst::ICMP_NE, Op0,
-                              Constant::getNullValue(Op1->getType()));
+                              Constant::getNullValue(Op1->getType(), &DL));
       }
       break;
     }
@@ -7182,8 +7193,8 @@ Instruction *InstCombinerImpl::foldICmpUsingBoolRange(ICmpInst &I) {
     bool IsSExt = ExtI->getOpcode() == Instruction::SExt;
     bool HasOneUse = ExtI->hasOneUse() && ExtI->getOperand(0)->hasOneUse();
     auto CreateRangeCheck = [&] {
-      Value *CmpV1 =
-          Builder.CreateICmp(Pred1, X, Constant::getNullValue(X->getType()));
+      Value *CmpV1 = Builder.CreateICmp(
+          Pred1, X, Constant::getNullValue(X->getType(), &DL));
       Value *CmpV2 = Builder.CreateICmp(
           Pred1, X, ConstantInt::getSigned(X->getType(), IsSExt ? -1 : 1));
       return BinaryOperator::Create(
@@ -7404,7 +7415,8 @@ static Instruction *foldICmpWithHighBitMask(ICmpInst &Cmp,
     return nullptr;
 
   Value *NewX = Builder.CreateLShr(X, Y, X->getName() + ".highbits");
-  Constant *Zero = Constant::getNullValue(NewX->getType());
+  Constant *Zero =
+      Constant::getNullValue(NewX->getType(), &Cmp.getDataLayout());
   return CmpInst::Create(Instruction::ICmp, NewPred, NewX, Zero);
 }
 
@@ -7656,7 +7668,7 @@ Instruction *InstCombinerImpl::foldICmpCommutative(CmpPredicate Pred,
     Constant *C;
     if (match(Op0, m_Intrinsic<Intrinsic::abs>(m_Value(X), m_Constant(C))) &&
         match(Op1, m_Specific(X))) {
-      Value *NullValue = Constant::getNullValue(X->getType());
+      Value *NullValue = Constant::getNullValue(X->getType(), &DL);
       Value *AllOnesValue = Constant::getAllOnesValue(X->getType());
       const APInt SMin =
           APInt::getSignedMinValue(X->getType()->getScalarSizeInBits());
@@ -7701,13 +7713,13 @@ Instruction *InstCombinerImpl::foldICmpCommutative(CmpPredicate Pred,
   {
     if (match(Op0, m_UDiv(m_Specific(Op1), m_CheckedInt(CheckUGT1)))) {
       return new ICmpInst(ICmpInst::getSwappedPredicate(Pred), Op1,
-                          Constant::getNullValue(Op1->getType()));
+                          Constant::getNullValue(Op1->getType(), &DL));
     }
 
     if (!ICmpInst::isUnsigned(Pred) &&
         match(Op0, m_SDiv(m_Specific(Op1), m_CheckedInt(CheckUGT1)))) {
       return new ICmpInst(ICmpInst::getSwappedPredicate(Pred), Op1,
-                          Constant::getNullValue(Op1->getType()));
+                          Constant::getNullValue(Op1->getType(), &DL));
     }
   }
 
@@ -7716,13 +7728,13 @@ Instruction *InstCombinerImpl::foldICmpCommutative(CmpPredicate Pred,
   {
     if (match(Op0, m_LShr(m_Specific(Op1), m_CheckedInt(CheckNE0)))) {
       return new ICmpInst(ICmpInst::getSwappedPredicate(Pred), Op1,
-                          Constant::getNullValue(Op1->getType()));
+                          Constant::getNullValue(Op1->getType(), &DL));
     }
 
     if ((Pred == CmpInst::ICMP_SLT || Pred == CmpInst::ICMP_SGE) &&
         match(Op0, m_AShr(m_Specific(Op1), m_CheckedInt(CheckNE0)))) {
       return new ICmpInst(ICmpInst::getSwappedPredicate(Pred), Op1,
-                          Constant::getNullValue(Op1->getType()));
+                          Constant::getNullValue(Op1->getType(), &DL));
     }
   }
 
@@ -7823,7 +7835,7 @@ Instruction *InstCombinerImpl::visitICmpInst(ICmpInst &I) {
   if (match(Op1, m_APInt(C))) {
     // For i32: x >u 2147483647 -> x <s 0  -> true if sign bit set
     if (Pred == ICmpInst::ICMP_UGT && C->isMaxSignedValue()) {
-      Constant *Zero = Constant::getNullValue(Op0->getType());
+      Constant *Zero = Constant::getNullValue(Op0->getType(), &DL);
       return new ICmpInst(ICmpInst::ICMP_SLT, Op0, Zero);
     }
 
@@ -8020,8 +8032,8 @@ Instruction *InstCombinerImpl::visitICmpInst(ICmpInst &I) {
         unsigned ShiftOpc = ShiftI->getOpcode();
         if ((ExtOpc == Instruction::ZExt && ShiftOpc == Instruction::LShr) ||
             (ExtOpc == Instruction::SExt && ShiftOpc == Instruction::AShr)) {
-          Value *SLTZero =
-              Builder.CreateICmpSLT(X, Constant::getNullValue(X->getType()));
+          Value *SLTZero = Builder.CreateICmpSLT(
+              X, Constant::getNullValue(X->getType(), &DL));
           Value *Cmp = Builder.CreateICmp(Pred, SLTZero, Y, I.getName());
           return replaceInstUsesWith(I, Cmp);
         }
@@ -8834,7 +8846,7 @@ Instruction *InstCombinerImpl::visitFCmpInst(FCmpInst &I) {
     case FCmpInst::FCMP_UNE: // True if unordered or not equal
       // Canonicalize these to be 'fcmp uno %X, 0.0'.
       I.setPredicate(FCmpInst::FCMP_UNO);
-      I.setOperand(1, Constant::getNullValue(OpType));
+      I.setOperand(1, Constant::getNullValue(OpType, &DL));
       return &I;
 
     case FCmpInst::FCMP_ORD: // True if ordered (no nans)
@@ -8843,7 +8855,7 @@ Instruction *InstCombinerImpl::visitFCmpInst(FCmpInst &I) {
     case FCmpInst::FCMP_OLE: // True if ordered and less than or equal
       // Canonicalize these to be 'fcmp ord %X, 0.0'.
       I.setPredicate(FCmpInst::FCMP_ORD);
-      I.setOperand(1, Constant::getNullValue(OpType));
+      I.setOperand(1, Constant::getNullValue(OpType, &DL));
       return &I;
     }
   }
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
index 6707d1abf5ca0..834e32c496237 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
@@ -4538,7 +4538,7 @@ Instruction *InstCombinerImpl::visitSelectInst(SelectInst &SI) {
       return nullptr;
     Type *ElementType = Gep->getSourceElementType();
     Value *NewT = Idx;
-    Value *NewF = Constant::getNullValue(Idx->getType());
+    Value *NewF = Constant::getNullValue(Idx->getType(), &DL);
     if (Swap)
       std::swap(NewT, NewF);
     Value *NewSI =
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
index 5e099b00be920..938f3bc3fd587 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
@@ -1050,7 +1050,7 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Instruction *I,
         if (DemandedMask.isSubsetOf(Known.Zero) &&
             !match(I->getOperand(1), m_Zero()))
           return replaceOperand(
-              *I, 1, Constant::getNullValue(I->getOperand(1)->getType()));
+              *I, 1, Constant::getNullValue(I->getOperand(1)->getType(), &DL));
 
         // Mask in demanded space does nothing.
         // NOTE: We may have attributes associated with the return value of the
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index 04ebc7d43dc4d..3b21633a04f89 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -282,7 +282,7 @@ Value *InstCombinerImpl::EmitGEPOffsets(ArrayRef<GEPOperator *> GEPs,
   if (OneUseSum)
     Sum = Add(Sum, OneUseSum);
   if (!Sum)
-    return Constant::getNullValue(IdxTy);
+    return Constant::getNullValue(IdxTy, &DL);
   return Sum;
 }
 
@@ -1132,7 +1132,7 @@ InstCombinerImpl::foldBinOpOfSelectAndCastOfSelectCondition(BinaryOperator &I) {
     Constant *C;
 
     if (IsTrueArm) {
-      C = Constant::getNullValue(V->getType());
+      C = Constant::getNullValue(V->getType(), &DL);
     } else if (IsZExt) {
       unsigned BitWidth = V->getType()->getScalarSizeInBits();
       C = Constant::getIntegerValue(V->getType(), APInt(BitWidth, 1));
@@ -3376,7 +3376,7 @@ Instruction *InstCombinerImpl::visitGetElementPtrInst(GetElementPtrInst &GEP) {
     Type *EltTy = GTI.getIndexedType();
     if (EltTy->isSized() && DL.getTypeAllocSize(EltTy).isZero())
       if (!isa<Constant>(*I) || !match(I->get(), m_Zero())) {
-        *I = Constant::getNullValue(NewIndexType);
+        *I = Constant::getNullValue(NewIndexType, &DL);
         MadeChange = true;
       }
 
@@ -3482,7 +3482,7 @@ Instruction *InstCombinerImpl::visitGetElementPtrInst(GetElementPtrInst &GEP) {
                           GEP.getName() + ".split", GEP.getNoWrapFlags());
 
     SmallVector<Value *> BackIndices;
-    BackIndices.push_back(Constant::getNullValue(NewScalarIndexTy));
+    BackIndices.push_back(Constant::getNullValue(NewScalarIndexTy, &DL));
     append_range(BackIndices, drop_begin(Indices, IdxNum));
     return GetElementPtrInst::Create(
         GetElementPtrInst::getIndexedType(GEPEltType, FrontIndices), FrontGEP,
@@ -3975,7 +3975,7 @@ Instruction *InstCombinerImpl::visitAllocSite(Instruction &MI) {
         if (isa<LoadInst>(I)) {
           assert(KnowInitZero || KnowInitUndef);
           Replace = KnowInitUndef ? UndefValue::get(I->getType())
-                                  : Constant::getNullValue(I->getType());
+                                  : Constant::getNullValue(I->getType(), &DL);
         } else
           Replace = PoisonValue::get(I->getType());
         replaceInstUsesWith(*I, Replace);
@@ -4958,7 +4958,7 @@ Instruction *InstCombinerImpl::visitLandingPadInst(LandingPadInst &LI) {
         // Not an empty filter - it contains at least one null typeinfo.
         assert(NumTypeInfos > 0 && "Should have handled empty filter already!");
         Constant *TypeInfo =
-          Constant::getNullValue(FilterType->getElementType());
+            Constant::getNullValue(FilterType->getElementType(), &DL);
         // If this typeinfo is a catch-all then the filter can never match.
         if (isCatchAll(Personality, TypeInfo)) {
           // Throw the filter away.
@@ -5435,7 +5435,7 @@ Instruction *InstCombinerImpl::visitFreeze(FreezeInst &I) {
       return BestValue;
     };
 
-    Value *NullValue = Constant::getNullValue(Ty);
+    Value *NullValue = Constant::getNullValue(Ty, &DL);
     Value *BestValue = nullptr;
     for (auto *U : I.users()) {
       Value *V = NullValue;
diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
index 8286ecddafe99..bdcbc1ed1037c 100644
--- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -2647,7 +2647,8 @@ void ModuleAddressSanitizer::instrumentGlobals(IRBuilder<> &IRB,
 
     StructType *NewTy = StructType::get(Ty, RightRedZoneTy);
     Constant *NewInitializer = ConstantStruct::get(
-        NewTy, G->getInitializer(), Constant::getNullValue(RightRedZoneTy));
+        NewTy, G->getInitializer(),
+        Constant::getNullValue(RightRedZoneTy, &M.getDataLayout()));
 
     // Create a new global variable with enough space for a redzone.
     GlobalValue::LinkageTypes Linkage = G->getLinkage();
@@ -2681,7 +2682,8 @@ void ModuleAddressSanitizer::instrumentGlobals(IRBuilder<> &IRB,
     G->eraseFromParent();
     NewGlobals[i] = NewGlobal;
 
-    Constant *ODRIndicator = Constant::getNullValue(IntptrTy);
+    Constant *ODRIndicator =
+        Constant::getNullValue(IntptrTy, &M.getDataLayout());
     GlobalValue *InstrumentedGlobal = NewGlobal;
 
     bool CanUsePrivateAliases =
@@ -2700,11 +2702,11 @@ void ModuleAddressSanitizer::instrumentGlobals(IRBuilder<> &IRB,
     } else if (UseOdrIndicator) {
       // With local aliases, we need to provide another externally visible
       // symbol __odr_asan_XXX to detect ODR violation.
-      auto *ODRIndicatorSym =
-          new GlobalVariable(M, IRB.getInt8Ty(), false, Linkage,
-                             Constant::getNullValue(IRB.getInt8Ty()),
-                             kODRGenPrefix + NameForGlobal, nullptr,
-                             NewGlobal->getThreadLocalMode());
+      auto *ODRIndicatorSym = new GlobalVariable(
+          M, IRB.getInt8Ty(), false, Linkage,
+          Constant::getNullValue(IRB.getInt8Ty(), &M.getDataLayout()),
+          kODRGenPrefix + NameForGlobal, nullptr,
+          NewGlobal->getThreadLocalMode());
 
       // Set meaningful attributes for indicator symbol.
       ODRIndicatorSym->setVisibility(NewGlobal->getVisibility());
@@ -2721,7 +2723,7 @@ void ModuleAddressSanitizer::instrumentGlobals(IRBuilder<> &IRB,
         ConstantExpr::getPointerCast(Name, IntptrTy),
         ConstantExpr::getPointerCast(getOrCreateModuleName(), IntptrTy),
         ConstantInt::get(IntptrTy, MD.IsDynInit),
-        Constant::getNullValue(IntptrTy), ODRIndicator);
+        Constant::getNullValue(IntptrTy, &M.getDataLayout()), ODRIndicator);
 
     LLVM_DEBUG(dbgs() << "NEW GLOBAL: " << *NewGlobal << "\n");
 
@@ -3407,7 +3409,8 @@ void FunctionStackPoisoner::createDynamicAllocasInitStorage() {
   BasicBlock &FirstBB = *F.begin();
   IRBuilder<> IRB(dyn_cast<Instruction>(FirstBB.begin()));
   DynamicAllocaLayout = IRB.CreateAlloca(IntptrTy, nullptr);
-  IRB.CreateStore(Constant::getNullValue(IntptrTy), DynamicAllocaLayout);
+  IRB.CreateStore(Constant::getNullValue(IntptrTy, &F.getDataLayout()),
+                  DynamicAllocaLayout);
   DynamicAllocaLayout->setAlignment(Align(32));
 }
 
@@ -3635,7 +3638,7 @@ void FunctionStackPoisoner::processStaticAllocas() {
           kAsanOptionDetectUseAfterReturn, IRB.getInt32Ty());
       Value *UseAfterReturnIsEnabled = IRB.CreateICmpNE(
           IRB.CreateLoad(IRB.getInt32Ty(), OptionDetectUseAfterReturn),
-          Constant::getNullValue(IRB.getInt32Ty()));
+          Constant::getNullValue(IRB.getInt32Ty(), &F.getDataLayout()));
       Instruction *Term =
           SplitBlockAndInsertIfThen(UseAfterReturnIsEnabled, InsBefore, false);
       IRBuilder<> IRBIf(Term);
@@ -3658,8 +3661,8 @@ void FunctionStackPoisoner::processStaticAllocas() {
                                  ConstantInt::get(IntptrTy, LocalStackSize));
     }
     FakeStackPtr = IRB.CreateIntToPtr(FakeStackInt, PtrTy);
-    Value *NoFakeStack =
-        IRB.CreateICmpEQ(FakeStackInt, Constant::getNullValue(IntptrTy));
+    Value *NoFakeStack = IRB.CreateICmpEQ(
+        FakeStackInt, Constant::getNullValue(IntptrTy, &F.getDataLayout()));
     Instruction *Term =
         SplitBlockAndInsertIfThen(NoFakeStack, InsBefore, false);
     IRBuilder<> IRBIf(Term);
@@ -3674,8 +3677,8 @@ void FunctionStackPoisoner::processStaticAllocas() {
   } else {
     // void *FakeStack = nullptr;
     // void *LocalStackBase = alloca(LocalStackSize);
-    FakeStackInt = Constant::getNullValue(IntptrTy);
-    FakeStackPtr = Constant::getNullValue(PtrTy);
+    FakeStackInt = Constant::getNullValue(IntptrTy, &F.getDataLayout());
+    FakeStackPtr = Constant::getNullValue(PtrTy, &F.getDataLayout());
     LocalStackBase =
         DoDynamicAlloca ? createAllocaForLayout(IRB, L, true) : StaticAlloca;
     LocalStackBaseAlloca = LocalStackBase;
@@ -3765,8 +3768,8 @@ void FunctionStackPoisoner::processStaticAllocas() {
       //         __asan_stack_free_N(FakeStack, LocalStackSize)
       // else
       //     <This is not a fake stack; unpoison the redzones>
-      Value *Cmp =
-          IRBRet.CreateICmpNE(FakeStackInt, Constant::getNullValue(IntptrTy));
+      Value *Cmp = IRBRet.CreateICmpNE(
+          FakeStackInt, Constant::getNullValue(IntptrTy, &F.getDataLayout()));
       Instruction *ThenTerm, *ElseTerm;
       SplitBlockAndInsertIfThenElse(Cmp, Ret, &ThenTerm, &ElseTerm);
 
@@ -3782,7 +3785,7 @@ void FunctionStackPoisoner::processStaticAllocas() {
             ConstantInt::get(IntptrTy, ClassSize - ASan.LongSize / 8));
         Value *SavedFlagPtr = IRBPoison.CreateLoad(IntptrTy, SavedFlagPtrPtr);
         IRBPoison.CreateStore(
-            Constant::getNullValue(IRBPoison.getInt8Ty()),
+            Constant::getNullValue(IRBPoison.getInt8Ty(), &F.getDataLayout()),
             IRBPoison.CreateIntToPtr(SavedFlagPtr, IRBPoison.getPtrTy()));
       } else {
         // For larger frames call __asan_stack_free_*.
@@ -3827,7 +3830,7 @@ void FunctionStackPoisoner::handleDynamicAllocaCall(AllocaInst *AI) {
   const Align Alignment = std::max(Align(kAllocaRzSize), AI->getAlign());
   const uint64_t AllocaRedzoneMask = kAllocaRzSize - 1;
 
-  Value *Zero = Constant::getNullValue(IntptrTy);
+  Value *Zero = Constant::getNullValue(IntptrTy, &F.getDataLayout());
   Value *AllocaRzSize = ConstantInt::get(IntptrTy, kAllocaRzSize);
   Value *AllocaRzMask = ConstantInt::get(IntptrTy, AllocaRedzoneMask);
 
diff --git a/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp b/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
index f143b1b42e2c9..072a618148ab7 100644
--- a/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
+++ b/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
@@ -897,7 +897,8 @@ bool GCOVProfiler::emitProfileNotes(
         ArrayType *CounterTy = ArrayType::get(Type::getInt64Ty(*Ctx), Measured);
         GlobalVariable *Counters = new GlobalVariable(
             *M, CounterTy, false, GlobalValue::InternalLinkage,
-            Constant::getNullValue(CounterTy), "__llvm_gcov_ctr");
+            Constant::getNullValue(CounterTy, &M->getDataLayout()),
+            "__llvm_gcov_ctr");
         const llvm::Triple &Triple = M->getTargetTriple();
         if (Triple.getObjectFormat() == llvm::Triple::XCOFF)
           Counters->setSection("__llvm_gcov_ctr_section");
@@ -1348,10 +1349,11 @@ Function *GCOVProfiler::insertReset(
   for (const auto &I : CountersBySP) {
     GlobalVariable *GV = I.first;
     auto *GVTy = cast<ArrayType>(GV->getValueType());
-    Builder.CreateMemSet(GV, Constant::getNullValue(Type::getInt8Ty(C)),
-                         GVTy->getNumElements() *
-                             GVTy->getElementType()->getScalarSizeInBits() / 8,
-                         GV->getAlign());
+    Builder.CreateMemSet(
+        GV, Constant::getNullValue(Type::getInt8Ty(C), &M->getDataLayout()),
+        GVTy->getNumElements() * GVTy->getElementType()->getScalarSizeInBits() /
+            8,
+        GV->getAlign());
   }
 
   Type *RetTy = ResetF->getReturnType();
diff --git a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
index fb8342aab1b2e..c5f9d8b94a7c3 100644
--- a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
@@ -626,7 +626,8 @@ void HWAddressSanitizer::createHwasanNote() {
   // always create start and stop symbols.
   auto *Dummy = new GlobalVariable(
       M, Int8Arr0Ty, /*isConstantGlobal*/ true, GlobalVariable::PrivateLinkage,
-      Constant::getNullValue(Int8Arr0Ty), "hwasan.dummy.global");
+      Constant::getNullValue(Int8Arr0Ty, &M.getDataLayout()),
+      "hwasan.dummy.global");
   Dummy->setSection("hwasan_globals");
   Dummy->setComdat(NoteComdat);
   Dummy->setMetadata(LLVMContext::MD_associated,
@@ -1898,7 +1899,7 @@ void HWAddressSanitizer::instrumentPersonalityFunctions() {
         HwasanPersonalityWrapper,
         {ThunkFn->getArg(0), ThunkFn->getArg(1), ThunkFn->getArg(2),
          ThunkFn->getArg(3), ThunkFn->getArg(4),
-         P.first ? P.first : Constant::getNullValue(PtrTy),
+         P.first ? P.first : Constant::getNullValue(PtrTy, &M.getDataLayout()),
          UnwindGetGR.getCallee(), UnwindGetCFA.getCallee()});
     WrapperCall->setTailCall();
     IRB.CreateRet(WrapperCall);
diff --git a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
index d96c84470bcbe..919cb97e4bee1 100644
--- a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
+++ b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
@@ -1095,7 +1095,8 @@ GlobalVariable *InstrLowerer::getOrCreateBiasVar(StringRef VarName) {
   // is being used. Runtime has a weak external reference that is used
   // to check whether that's the case or not.
   Bias = new GlobalVariable(M, Int64Ty, false, GlobalValue::LinkOnceODRLinkage,
-                            Constant::getNullValue(Int64Ty), VarName);
+                            Constant::getNullValue(Int64Ty, &M.getDataLayout()),
+                            VarName);
   Bias->setVisibility(GlobalVariable::HiddenVisibility);
   // A definition that's weak (linkonce_odr) without being in a COMDAT
   // section wouldn't lead to link errors, but it would lead to a dead
@@ -1624,8 +1625,9 @@ InstrLowerer::createRegionBitmaps(InstrProfMCDCBitmapInstBase *Inc,
                                   GlobalValue::LinkageTypes Linkage) {
   uint64_t NumBytes = Inc->getNumBitmapBytes();
   auto *BitmapTy = ArrayType::get(Type::getInt8Ty(M.getContext()), NumBytes);
-  auto GV = new GlobalVariable(M, BitmapTy, false, Linkage,
-                               Constant::getNullValue(BitmapTy), Name);
+  auto GV = new GlobalVariable(
+      M, BitmapTy, false, Linkage,
+      Constant::getNullValue(BitmapTy, &M.getDataLayout()), Name);
   GV->setAlignment(Align(1));
   return GV;
 }
@@ -1664,8 +1666,9 @@ InstrLowerer::createRegionCounters(InstrProfCntrInstBase *Inc, StringRef Name,
     GV->setAlignment(Align(1));
   } else {
     auto *CounterTy = ArrayType::get(Type::getInt64Ty(Ctx), NumCounters);
-    GV = new GlobalVariable(M, CounterTy, false, Linkage,
-                            Constant::getNullValue(CounterTy), Name);
+    GV = new GlobalVariable(
+        M, CounterTy, false, Linkage,
+        Constant::getNullValue(CounterTy, &M.getDataLayout()), Name);
     GV->setAlignment(Align(8));
   }
   return GV;
@@ -1774,7 +1777,8 @@ void InstrLowerer::createDataVariable(InstrProfCntrInstBase *Inc) {
       !needsRuntimeRegistrationOfSectionRange(TT)) {
     ArrayType *ValuesTy = ArrayType::get(Type::getInt64Ty(Ctx), NS);
     auto *ValuesVar = new GlobalVariable(
-        M, ValuesTy, false, Linkage, Constant::getNullValue(ValuesTy),
+        M, ValuesTy, false, Linkage,
+        Constant::getNullValue(ValuesTy, &M.getDataLayout()),
         getVarName(Inc, getInstrProfValuesVarPrefix(), Renamed));
     ValuesVar->setVisibility(Visibility);
     setGlobalVariableLargeSection(TT, *ValuesVar);
@@ -1918,9 +1922,10 @@ void InstrLowerer::emitVNodes() {
   auto *VNodeTy = StructType::get(Ctx, ArrayRef(VNodeTypes));
 
   ArrayType *VNodesTy = ArrayType::get(VNodeTy, NumCounters);
-  auto *VNodesVar = new GlobalVariable(
-      M, VNodesTy, false, GlobalValue::PrivateLinkage,
-      Constant::getNullValue(VNodesTy), getInstrProfVNodesVarName());
+  auto *VNodesVar =
+      new GlobalVariable(M, VNodesTy, false, GlobalValue::PrivateLinkage,
+                         Constant::getNullValue(VNodesTy, &M.getDataLayout()),
+                         getInstrProfVNodesVarName());
   setGlobalVariableLargeSection(TT, *VNodesVar);
   VNodesVar->setSection(
       getInstrProfSectionName(IPSK_vnodes, TT.getObjectFormat()));
diff --git a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
index e257b9304f6e6..8612289ecf155 100644
--- a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
@@ -2004,7 +2004,7 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
     Type *ShadowTy = getShadowTy(OrigTy);
     if (!ShadowTy)
       return nullptr;
-    return Constant::getNullValue(ShadowTy);
+    return Constant::getNullValue(ShadowTy, &F.getDataLayout());
   }
 
   /// Create a clean shadow value for a given value.
@@ -2042,7 +2042,9 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
   }
 
   /// Create a clean (zero) origin.
-  Value *getCleanOrigin() { return Constant::getNullValue(MS.OriginTy); }
+  Value *getCleanOrigin() {
+    return Constant::getNullValue(MS.OriginTy, &F.getDataLayout());
+  }
 
   /// Get the shadow value for a given Value.
   ///
@@ -2108,9 +2110,10 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
                                    /*isStore*/ true);
             if (!PropagateShadow || Overflow) {
               // ParamTLS overflow.
-              EntryIRB.CreateMemSet(
-                  CpShadowPtr, Constant::getNullValue(EntryIRB.getInt8Ty()),
-                  Size, ArgAlign);
+              EntryIRB.CreateMemSet(CpShadowPtr,
+                                    Constant::getNullValue(EntryIRB.getInt8Ty(),
+                                                           &F->getDataLayout()),
+                                    Size, ArgAlign);
             } else {
               Value *Base = getShadowPtrForArgument(EntryIRB, ArgOffset);
               const Align CopyAlign = std::min(ArgAlign, kShadowTLSAlignment);
@@ -2461,7 +2464,7 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
     // * there is a defined 1 bit in C
     // * C is fully defined
     // Si = !(C & ~Sc) && Sc
-    Value *Zero = Constant::getNullValue(Sc->getType());
+    Value *Zero = Constant::getNullValue(Sc->getType(), &F.getDataLayout());
     Value *MinusOne = Constant::getAllOnesValue(Sc->getType());
     Value *LHS = IRB.CreateICmpNE(Sc, Zero);
     Value *RHS =
@@ -3889,10 +3892,10 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
       S1 = IRB.CreateBitCast(S1, T);
       S2 = IRB.CreateBitCast(S2, T);
     }
-    Value *S1_ext =
-        IRB.CreateSExt(IRB.CreateICmpNE(S1, Constant::getNullValue(T)), T);
-    Value *S2_ext =
-        IRB.CreateSExt(IRB.CreateICmpNE(S2, Constant::getNullValue(T)), T);
+    Value *S1_ext = IRB.CreateSExt(
+        IRB.CreateICmpNE(S1, Constant::getNullValue(T, &F.getDataLayout())), T);
+    Value *S2_ext = IRB.CreateSExt(
+        IRB.CreateICmpNE(S2, Constant::getNullValue(T, &F.getDataLayout())), T);
     if (MMXEltSizeInBits) {
       S1_ext = IRB.CreateBitCast(S1_ext, getMMXVectorTy(64));
       S2_ext = IRB.CreateBitCast(S2_ext, getMMXVectorTy(64));
@@ -3925,14 +3928,17 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
     const unsigned Width =
         cast<FixedVectorType>(S->getType())->getNumElements();
 
-    S = IRB.CreateSelect(createDppMask(Width, SrcMask), S,
-                         Constant::getNullValue(S->getType()));
+    S = IRB.CreateSelect(
+        createDppMask(Width, SrcMask), S,
+        Constant::getNullValue(S->getType(), &F.getDataLayout()));
     Value *SElem = IRB.CreateOrReduce(S);
     Value *IsClean = IRB.CreateIsNull(SElem, "_msdpp");
     Value *DstMaskV = createDppMask(Width, DstMask);
 
     return IRB.CreateSelect(
-        IsClean, Constant::getNullValue(DstMaskV->getType()), DstMaskV);
+        IsClean,
+        Constant::getNullValue(DstMaskV->getType(), &F.getDataLayout()),
+        DstMaskV);
   }
 
   // See `Intel Intrinsics Guide` for `_dp_p*` instructions.
@@ -4020,8 +4026,9 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
     auto *Shadow1 = getShadow(&I, 1);
     Value *S = IRB.CreateOr(Shadow0, Shadow1);
     S = IRB.CreateBitCast(S, ResTy);
-    S = IRB.CreateSExt(IRB.CreateICmpNE(S, Constant::getNullValue(ResTy)),
-                       ResTy);
+    S = IRB.CreateSExt(
+        IRB.CreateICmpNE(S, Constant::getNullValue(ResTy, &F.getDataLayout())),
+        ResTy);
     S = IRB.CreateLShr(S, ZeroBitsPerResultElement);
     S = IRB.CreateBitCast(S, getShadowTy(&I));
     setShadow(&I, S);
@@ -4178,8 +4185,9 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
 
     // Compute <4 x i1>, then extend back to <4 x i32>.
     Value *OutShadow = IRB.CreateSExt(
-        IRB.CreateICmpNE(Horizontal,
-                         Constant::getNullValue(Horizontal->getType())),
+        IRB.CreateICmpNE(
+            Horizontal,
+            Constant::getNullValue(Horizontal->getType(), &F.getDataLayout())),
         ImplicitReturnType);
 
     // Cast it back to the required fake return type (if MMX: <1 x i64>; for
@@ -4226,7 +4234,8 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
     auto *Shadow1 = getShadow(&I, 1);
     Value *S0 = IRB.CreateOr(Shadow0, Shadow1);
     Value *S = IRB.CreateSExt(
-        IRB.CreateICmpNE(S0, Constant::getNullValue(ResTy)), ResTy);
+        IRB.CreateICmpNE(S0, Constant::getNullValue(ResTy, &F.getDataLayout())),
+        ResTy);
     setShadow(&I, S);
     setOriginForNaryOp(I);
   }
@@ -4423,7 +4432,8 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
     if (ClCheckAccessAddress) {
       insertCheckShadowOf(Mask, &I);
       Value *MaskedPtrShadow = IRB.CreateSelect(
-          Mask, getShadow(Ptrs), Constant::getNullValue((PtrsShadowTy)),
+          Mask, getShadow(Ptrs),
+          Constant::getNullValue((PtrsShadowTy), &F.getDataLayout()),
           "_msmaskedptrs");
       insertCheckShadow(MaskedPtrShadow, getOrigin(Ptrs), &I);
     }
@@ -4460,7 +4470,8 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
     if (ClCheckAccessAddress) {
       insertCheckShadowOf(Mask, &I);
       Value *MaskedPtrShadow = IRB.CreateSelect(
-          Mask, getShadow(Ptrs), Constant::getNullValue((PtrsShadowTy)),
+          Mask, getShadow(Ptrs),
+          Constant::getNullValue((PtrsShadowTy), &F.getDataLayout()),
           "_msmaskedptrs");
       insertCheckShadow(MaskedPtrShadow, getOrigin(Ptrs), &I);
     }
@@ -4942,7 +4953,8 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
     Value *Shadow0 = getShadow(&I, 0);
     Value *Shadow1 = getShadow(&I, 1);
     Value *Or = IRB.CreateOr(Shadow0, Shadow1);
-    Value *NZ = IRB.CreateICmpNE(Or, Constant::getNullValue(Or->getType()));
+    Value *NZ = IRB.CreateICmpNE(
+        Or, Constant::getNullValue(Or->getType(), &F.getDataLayout()));
     Value *Scalar = convertShadowToScalar(NZ, IRB);
     Value *Shadow = IRB.CreateZExt(Scalar, getShadowTy(&I));
 
@@ -7347,9 +7359,10 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
               getShadowOriginPtr(A, IRB, IRB.getInt8Ty(), Alignment,
                                  /*isStore*/ false);
           if (!PropagateShadow) {
-            Store = IRB.CreateMemSet(ArgShadowBase,
-                                     Constant::getNullValue(IRB.getInt8Ty()),
-                                     Size, Alignment);
+            Store = IRB.CreateMemSet(
+                ArgShadowBase,
+                Constant::getNullValue(IRB.getInt8Ty(), &F.getDataLayout()),
+                Size, Alignment);
           } else {
             Store = IRB.CreateMemCpy(ArgShadowBase, Alignment, AShadowPtr,
                                      Alignment, Size);
@@ -7922,8 +7935,9 @@ struct VarArgHelperBase : public VarArgHelper {
     auto [ShadowPtr, OriginPtr] = MSV.getShadowOriginPtr(
         VAListTag, IRB, IRB.getInt8Ty(), Alignment, /*isStore*/ true);
     // Unpoison the whole __va_list_tag.
-    IRB.CreateMemSet(ShadowPtr, Constant::getNullValue(IRB.getInt8Ty()),
-                     VAListTagSize, Alignment, false);
+    IRB.CreateMemSet(
+        ShadowPtr, Constant::getNullValue(IRB.getInt8Ty(), &F.getDataLayout()),
+        VAListTagSize, Alignment, false);
   }
 
   void visitVAStartInst(VAStartInst &I) override {
@@ -8104,8 +8118,10 @@ struct VarArgAMD64Helper : public VarArgHelperBase {
           ConstantInt::get(MS.IntptrTy, AMD64FpEndOffset), VAArgOverflowSize);
       VAArgTLSCopy = IRB.CreateAlloca(Type::getInt8Ty(*MS.C), CopySize);
       VAArgTLSCopy->setAlignment(kShadowTLSAlignment);
-      IRB.CreateMemSet(VAArgTLSCopy, Constant::getNullValue(IRB.getInt8Ty()),
-                       CopySize, kShadowTLSAlignment, false);
+      IRB.CreateMemSet(
+          VAArgTLSCopy,
+          Constant::getNullValue(IRB.getInt8Ty(), &F.getDataLayout()), CopySize,
+          kShadowTLSAlignment, false);
 
       Value *SrcSize = IRB.CreateBinaryIntrinsic(
           Intrinsic::umin, CopySize,
@@ -8296,8 +8312,10 @@ struct VarArgAArch64Helper : public VarArgHelperBase {
           ConstantInt::get(MS.IntptrTy, AArch64VAEndOffset), VAArgOverflowSize);
       VAArgTLSCopy = IRB.CreateAlloca(Type::getInt8Ty(*MS.C), CopySize);
       VAArgTLSCopy->setAlignment(kShadowTLSAlignment);
-      IRB.CreateMemSet(VAArgTLSCopy, Constant::getNullValue(IRB.getInt8Ty()),
-                       CopySize, kShadowTLSAlignment, false);
+      IRB.CreateMemSet(
+          VAArgTLSCopy,
+          Constant::getNullValue(IRB.getInt8Ty(), &F.getDataLayout()), CopySize,
+          kShadowTLSAlignment, false);
 
       Value *SrcSize = IRB.CreateBinaryIntrinsic(
           Intrinsic::umin, CopySize,
@@ -8508,8 +8526,10 @@ struct VarArgPowerPC64Helper : public VarArgHelperBase {
 
       VAArgTLSCopy = IRB.CreateAlloca(Type::getInt8Ty(*MS.C), CopySize);
       VAArgTLSCopy->setAlignment(kShadowTLSAlignment);
-      IRB.CreateMemSet(VAArgTLSCopy, Constant::getNullValue(IRB.getInt8Ty()),
-                       CopySize, kShadowTLSAlignment, false);
+      IRB.CreateMemSet(
+          VAArgTLSCopy,
+          Constant::getNullValue(IRB.getInt8Ty(), &F.getDataLayout()), CopySize,
+          kShadowTLSAlignment, false);
 
       Value *SrcSize = IRB.CreateBinaryIntrinsic(
           Intrinsic::umin, CopySize,
@@ -8644,8 +8664,10 @@ struct VarArgPowerPC32Helper : public VarArgHelperBase {
 
       VAArgTLSCopy = IRB.CreateAlloca(Type::getInt8Ty(*MS.C), CopySize);
       VAArgTLSCopy->setAlignment(kShadowTLSAlignment);
-      IRB.CreateMemSet(VAArgTLSCopy, Constant::getNullValue(IRB.getInt8Ty()),
-                       CopySize, kShadowTLSAlignment, false);
+      IRB.CreateMemSet(
+          VAArgTLSCopy,
+          Constant::getNullValue(IRB.getInt8Ty(), &F.getDataLayout()), CopySize,
+          kShadowTLSAlignment, false);
 
       Value *SrcSize = IRB.CreateBinaryIntrinsic(
           Intrinsic::umin, CopySize,
@@ -8980,8 +9002,10 @@ struct VarArgSystemZHelper : public VarArgHelperBase {
                         VAArgOverflowSize);
       VAArgTLSCopy = IRB.CreateAlloca(Type::getInt8Ty(*MS.C), CopySize);
       VAArgTLSCopy->setAlignment(kShadowTLSAlignment);
-      IRB.CreateMemSet(VAArgTLSCopy, Constant::getNullValue(IRB.getInt8Ty()),
-                       CopySize, kShadowTLSAlignment, false);
+      IRB.CreateMemSet(
+          VAArgTLSCopy,
+          Constant::getNullValue(IRB.getInt8Ty(), &F.getDataLayout()), CopySize,
+          kShadowTLSAlignment, false);
 
       Value *SrcSize = IRB.CreateBinaryIntrinsic(
           Intrinsic::umin, CopySize,
@@ -9083,8 +9107,10 @@ struct VarArgI386Helper : public VarArgHelperBase {
       // va_arg_tls somewhere in the function entry block.
       VAArgTLSCopy = IRB.CreateAlloca(Type::getInt8Ty(*MS.C), CopySize);
       VAArgTLSCopy->setAlignment(kShadowTLSAlignment);
-      IRB.CreateMemSet(VAArgTLSCopy, Constant::getNullValue(IRB.getInt8Ty()),
-                       CopySize, kShadowTLSAlignment, false);
+      IRB.CreateMemSet(
+          VAArgTLSCopy,
+          Constant::getNullValue(IRB.getInt8Ty(), &F.getDataLayout()), CopySize,
+          kShadowTLSAlignment, false);
 
       Value *SrcSize = IRB.CreateBinaryIntrinsic(
           Intrinsic::umin, CopySize,
@@ -9168,8 +9194,10 @@ struct VarArgGenericHelper : public VarArgHelperBase {
       // va_arg_tls somewhere in the function entry block.
       VAArgTLSCopy = IRB.CreateAlloca(Type::getInt8Ty(*MS.C), CopySize);
       VAArgTLSCopy->setAlignment(kShadowTLSAlignment);
-      IRB.CreateMemSet(VAArgTLSCopy, Constant::getNullValue(IRB.getInt8Ty()),
-                       CopySize, kShadowTLSAlignment, false);
+      IRB.CreateMemSet(
+          VAArgTLSCopy,
+          Constant::getNullValue(IRB.getInt8Ty(), &F.getDataLayout()), CopySize,
+          kShadowTLSAlignment, false);
 
       Value *SrcSize = IRB.CreateBinaryIntrinsic(
           Intrinsic::umin, CopySize,
diff --git a/llvm/lib/Transforms/Instrumentation/PGOCtxProfLowering.cpp b/llvm/lib/Transforms/Instrumentation/PGOCtxProfLowering.cpp
index 8c75942465aa4..b82c4b7fa4544 100644
--- a/llvm/lib/Transforms/Instrumentation/PGOCtxProfLowering.cpp
+++ b/llvm/lib/Transforms/Instrumentation/PGOCtxProfLowering.cpp
@@ -139,9 +139,10 @@ CtxInstrumentationLowerer::CtxInstrumentationLowerer(Module &M,
 #undef _MUTEXDECL
 
   const auto &DL = M.getDataLayout();
-#define _PTRDECL(_, __) Constant::getNullValue(PointerTy),
+#define _PTRDECL(_, __) Constant::getNullValue(PointerTy, &M.getDataLayout()),
 #define _VOLATILE_PTRDECL(_, __) _PTRDECL(_, __)
-#define _MUTEXDECL(_) Constant::getNullValue(SanitizerMutexType),
+#define _MUTEXDECL(_)                                                          \
+  Constant::getNullValue(SanitizerMutexType, &M.getDataLayout()),
 #define _CONTEXT_ROOT                                                          \
   Constant::getIntegerValue(                                                   \
       PointerTy, APInt(DL.getPointerTypeSizeInBits(PointerTy), 1U)),
@@ -303,8 +304,9 @@ bool CtxInstrumentationLowerer::lowerFunction(Function &F) {
       // treated as a "can't be set as root".
       TheRootFunctionData = new GlobalVariable(
           M, FunctionDataTy, false, GlobalVariable::InternalLinkage,
-          HasMusttail ? CannotBeRootInitializer
-                      : Constant::getNullValue(FunctionDataTy));
+          HasMusttail
+              ? CannotBeRootInitializer
+              : Constant::getNullValue(FunctionDataTy, &M.getDataLayout()));
 
       if (ContextRootSet.contains(&F)) {
         Context = Builder.CreateCall(
diff --git a/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp b/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
index 4d1471e7b15ba..2e173abd443a2 100644
--- a/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
+++ b/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
@@ -520,7 +520,7 @@ bool ModuleSanitizerCoverage::instrumentModule() {
         M.getOrInsertGlobal(SanCovCallbackGateName, Int64Ty));
     SanCovCallbackGate->setSection(
         getSectionName(SanCovCallbackGateSectionName));
-    SanCovCallbackGate->setInitializer(Constant::getNullValue(Int64Ty));
+    SanCovCallbackGate->setInitializer(Constant::getNullValue(Int64Ty, DL));
     SanCovCallbackGate->setLinkage(GlobalVariable::LinkOnceAnyLinkage);
     SanCovCallbackGate->setVisibility(GlobalVariable::HiddenVisibility);
     appendToCompilerUsed(M, SanCovCallbackGate);
@@ -759,7 +759,7 @@ GlobalVariable *ModuleSanitizerCoverage::CreateFunctionLocalArrayInSection(
   ArrayType *ArrayTy = ArrayType::get(Ty, NumElements);
   auto Array = new GlobalVariable(
       *CurModule, ArrayTy, false, GlobalVariable::PrivateLinkage,
-      Constant::getNullValue(ArrayTy), "__sancov_gen_");
+      Constant::getNullValue(ArrayTy, DL), "__sancov_gen_");
 
   if (TargetTriple.supportsCOMDAT() &&
       (F.hasComdat() || TargetTriple.isOSBinFormatELF() || !F.isInterposable()))
@@ -800,7 +800,7 @@ ModuleSanitizerCoverage::CreatePCArray(Function &F,
     } else {
       PCs.push_back((Constant *)IRB.CreatePointerCast(
           BlockAddress::get(AllBlocks[i]), PtrTy));
-      PCs.push_back(Constant::getNullValue(PtrTy));
+      PCs.push_back(Constant::getNullValue(PtrTy, DL));
     }
   }
   auto *PCArray =
@@ -1148,7 +1148,7 @@ void ModuleSanitizerCoverage::InjectCoverageAtBlock(Function &F, BasicBlock &BB,
       // Check stack depth.  If it's the deepest so far, record it.
       auto FrameAddrPtr = IRB.CreateIntrinsic(
           Intrinsic::frameaddress, IRB.getPtrTy(DL.getAllocaAddrSpace()),
-          {Constant::getNullValue(Int32Ty)});
+          {Constant::getNullValue(Int32Ty, &DL)});
       auto FrameAddrInt = IRB.CreatePtrToInt(FrameAddrPtr, IntptrTy);
       auto LowestStack = IRB.CreateLoad(IntptrTy, SanCovLowestStack);
       auto IsStackLower = IRB.CreateICmpULT(FrameAddrInt, LowestStack);
@@ -1213,7 +1213,7 @@ void ModuleSanitizerCoverage::createFunctionControlFlow(Function &F) {
           (Constant *)IRB.CreatePointerCast(BlockAddress::get(SuccBB), PtrTy));
     }
 
-    CFs.push_back((Constant *)Constant::getNullValue(PtrTy));
+    CFs.push_back((Constant *)Constant::getNullValue(PtrTy, DL));
 
     for (auto &Inst : BB) {
       if (CallBase *CB = dyn_cast<CallBase>(&Inst)) {
@@ -1229,7 +1229,7 @@ void ModuleSanitizerCoverage::createFunctionControlFlow(Function &F) {
       }
     }
 
-    CFs.push_back((Constant *)Constant::getNullValue(PtrTy));
+    CFs.push_back((Constant *)Constant::getNullValue(PtrTy, DL));
   }
 
   FunctionCFsArray = CreateFunctionLocalArrayInSection(CFs.size(), F, PtrTy,
diff --git a/llvm/lib/Transforms/Instrumentation/TypeSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/TypeSanitizer.cpp
index 28c640f719e87..b6ea5c52e2ae5 100644
--- a/llvm/lib/Transforms/Instrumentation/TypeSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/TypeSanitizer.cpp
@@ -629,7 +629,7 @@ bool TypeSanitizer::instrumentWithShadowUpdate(
   if (TBAAMD)
     TDGV = TypeDescriptors[TBAAMD];
   else
-    TDGV = Constant::getNullValue(IRB.getPtrTy());
+    TDGV = Constant::getNullValue(IRB.getPtrTy(), &DL);
 
   Value *TD = IRB.CreateBitCast(TDGV, IRB.getPtrTy());
 
diff --git a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
index fc5ee2359a76f..426230f0b278c 100644
--- a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
@@ -780,7 +780,7 @@ ConstraintInfo::getConstraint(CmpInst::Predicate Pred, Value *Op0, Value *Op1,
 ConstraintTy ConstraintInfo::getConstraintForSolving(CmpInst::Predicate Pred,
                                                      Value *Op0,
                                                      Value *Op1) const {
-  Constant *NullC = Constant::getNullValue(Op0->getType());
+  Constant *NullC = Constant::getNullValue(Op0->getType(), &DL);
   // Handle trivially true compares directly to avoid adding V UGE 0 constraints
   // for all variables in the unsigned system.
   if ((Pred == CmpInst::ICMP_ULE && Op0 == NullC) ||
diff --git a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
index fe257814aeed8..a54d3df97d550 100644
--- a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
+++ b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
@@ -829,7 +829,8 @@ static bool expandUDivOrURem(BinaryOperator *Instr, const ConstantRange &XCR,
   // X u/ Y -> 0  iff X u< Y
   // X u% Y -> X  iff X u< Y
   if (XCR.icmp(ICmpInst::ICMP_ULT, YCR)) {
-    Instr->replaceAllUsesWith(IsRem ? X : Constant::getNullValue(Ty));
+    Instr->replaceAllUsesWith(
+        IsRem ? X : Constant::getNullValue(Ty, &Instr->getDataLayout()));
     Instr->eraseFromParent();
     ++NumUDivURemsNarrowedExpanded;
     return true;
diff --git a/llvm/lib/Transforms/Scalar/GVN.cpp b/llvm/lib/Transforms/Scalar/GVN.cpp
index 6033707ff0b20..0d7cc5799ccb7 100644
--- a/llvm/lib/Transforms/Scalar/GVN.cpp
+++ b/llvm/lib/Transforms/Scalar/GVN.cpp
@@ -2094,7 +2094,9 @@ bool GVNPass::processAssumeIntrinsic(AssumeInst *IntrinsicI) {
       // this code is not reachable.  FIXME: We could insert unreachable
       // instruction directly because we can modify the CFG.
       auto *NewS =
-          new StoreInst(PoisonValue::get(Int8Ty), Constant::getNullValue(PtrTy),
+          new StoreInst(PoisonValue::get(Int8Ty),
+                        Constant::getNullValue(
+                            PtrTy, &IntrinsicI->getModule()->getDataLayout()),
                         IntrinsicI->getIterator());
       if (MSSAU) {
         const MemoryUseOrDef *FirstNonDom = nullptr;
diff --git a/llvm/lib/Transforms/Scalar/InferAlignment.cpp b/llvm/lib/Transforms/Scalar/InferAlignment.cpp
index a08f70ac188a6..772f7affa7b4a 100644
--- a/llvm/lib/Transforms/Scalar/InferAlignment.cpp
+++ b/llvm/lib/Transforms/Scalar/InferAlignment.cpp
@@ -47,7 +47,7 @@ static bool tryToImproveAlign(
   if (match(I, m_And(m_PtrToIntOrAddr(m_Value(PtrOp)), m_APInt(Const)))) {
     Align ActualAlign = Fn(PtrOp, Align(1), Align(1));
     if (Const->ult(ActualAlign.value())) {
-      I->replaceAllUsesWith(Constant::getNullValue(I->getType()));
+      I->replaceAllUsesWith(Constant::getNullValue(I->getType(), &DL));
       return true;
     }
     if (Const->uge(
@@ -59,7 +59,7 @@ static bool tryToImproveAlign(
   if (match(I, m_Trunc(m_PtrToIntOrAddr(m_Value(PtrOp))))) {
     Align ActualAlign = Fn(PtrOp, Align(1), Align(1));
     if (Log2(ActualAlign) >= I->getType()->getScalarSizeInBits()) {
-      I->replaceAllUsesWith(Constant::getNullValue(I->getType()));
+      I->replaceAllUsesWith(Constant::getNullValue(I->getType(), &DL));
       return true;
     }
   }
diff --git a/llvm/lib/Transforms/Scalar/NewGVN.cpp b/llvm/lib/Transforms/Scalar/NewGVN.cpp
index 2fbd2bd99fd76..62b0106909f94 100644
--- a/llvm/lib/Transforms/Scalar/NewGVN.cpp
+++ b/llvm/lib/Transforms/Scalar/NewGVN.cpp
@@ -3756,7 +3756,7 @@ void NewGVN::deleteInstructionsInBlock(BasicBlock *BB) {
   Type *Int8Ty = Type::getInt8Ty(BB->getContext());
   new StoreInst(
       PoisonValue::get(Int8Ty),
-      Constant::getNullValue(PointerType::getUnqual(BB->getContext())),
+      Constant::getNullValue(PointerType::getUnqual(BB->getContext()), &DL),
       BB->getTerminator()->getIterator());
 }
 
diff --git a/llvm/lib/Transforms/Scalar/Reassociate.cpp b/llvm/lib/Transforms/Scalar/Reassociate.cpp
index 010ff6e1fa5b4..a9c2df03cadd3 100644
--- a/llvm/lib/Transforms/Scalar/Reassociate.cpp
+++ b/llvm/lib/Transforms/Scalar/Reassociate.cpp
@@ -297,7 +297,8 @@ static BinaryOperator *LowerNegateToMultiply(Instruction *Neg) {
 
   BinaryOperator *Res =
       CreateMul(Neg->getOperand(OpNo), NegOne, "", Neg->getIterator(), Neg);
-  Neg->setOperand(OpNo, Constant::getNullValue(Ty)); // Drop use of op.
+  Neg->setOperand(OpNo, Constant::getNullValue(
+                            Ty, &Neg->getDataLayout())); // Drop use of op.
   Res->takeName(Neg);
   Neg->replaceAllUsesWith(Res);
   Res->setDebugLoc(Neg->getDebugLoc());
@@ -1007,8 +1008,12 @@ static BinaryOperator *BreakUpSubtract(Instruction *Sub,
   Value *NegVal = NegateValue(Sub->getOperand(1), Sub, ToRedo);
   BinaryOperator *New =
       CreateAdd(Sub->getOperand(0), NegVal, "", Sub->getIterator(), Sub);
-  Sub->setOperand(0, Constant::getNullValue(Sub->getType())); // Drop use of op.
-  Sub->setOperand(1, Constant::getNullValue(Sub->getType())); // Drop use of op.
+  Sub->setOperand(
+      0, Constant::getNullValue(Sub->getType(),
+                                &Sub->getDataLayout())); // Drop use of op.
+  Sub->setOperand(
+      1, Constant::getNullValue(Sub->getType(),
+                                &Sub->getDataLayout())); // Drop use of op.
   New->takeName(Sub);
 
   // Everyone now refers to the add instruction.
@@ -1553,7 +1558,7 @@ Value *ReassociatePass::OptimizeAdd(Instruction *I,
     // Remove X and -X from the operand list.
     if (Ops.size() == 2 &&
         (match(TheOp, m_Neg(m_Value())) || match(TheOp, m_FNeg(m_Value()))))
-      return Constant::getNullValue(X->getType());
+      return Constant::getNullValue(X->getType(), &I->getDataLayout());
 
     // Remove X and ~X from the operand list.
     if (Ops.size() == 2 && match(TheOp, m_Not(m_Value())))
diff --git a/llvm/lib/Transforms/Scalar/Reg2Mem.cpp b/llvm/lib/Transforms/Scalar/Reg2Mem.cpp
index 764662441a040..1144c081dc64d 100644
--- a/llvm/lib/Transforms/Scalar/Reg2Mem.cpp
+++ b/llvm/lib/Transforms/Scalar/Reg2Mem.cpp
@@ -64,7 +64,8 @@ static bool runPass(Function &F) {
   while (isa<AllocaInst>(I)) ++I;
 
   CastInst *AllocaInsertionPoint = new BitCastInst(
-      Constant::getNullValue(Type::getInt32Ty(F.getContext())),
+      Constant::getNullValue(Type::getInt32Ty(F.getContext()),
+                             &F.getDataLayout()),
       Type::getInt32Ty(F.getContext()), "reg2mem alloca point", I);
 
   // Find the escaped instructions. But don't create stack slots for
diff --git a/llvm/lib/Transforms/Utils/AMDGPUEmitPrintf.cpp b/llvm/lib/Transforms/Utils/AMDGPUEmitPrintf.cpp
index 0d85b16ef1c31..6a973b53fe100 100644
--- a/llvm/lib/Transforms/Utils/AMDGPUEmitPrintf.cpp
+++ b/llvm/lib/Transforms/Utils/AMDGPUEmitPrintf.cpp
@@ -117,8 +117,10 @@ static Value *getStrlenWithNull(IRBuilder<> &Builder, Value *Str) {
 
   // Emit an early return for when the pointer is null.
   Builder.SetInsertPoint(Prev);
-  auto CmpNull =
-      Builder.CreateICmpEQ(Str, Constant::getNullValue(Str->getType()));
+  auto CmpNull = Builder.CreateICmpEQ(
+      Str, Constant::getNullValue(
+               Str->getType(),
+               &Builder.GetInsertBlock()->getModule()->getDataLayout()));
   BranchInst::Create(Join, While, CmpNull, Prev);
 
   // Entry to the while loop.
diff --git a/llvm/lib/Transforms/Utils/CodeExtractor.cpp b/llvm/lib/Transforms/Utils/CodeExtractor.cpp
index b298a8ae144d8..f2f534234f2b1 100644
--- a/llvm/lib/Transforms/Utils/CodeExtractor.cpp
+++ b/llvm/lib/Transforms/Utils/CodeExtractor.cpp
@@ -1621,7 +1621,9 @@ void CodeExtractor::emitFunctionBody(
     Value *RewriteVal;
     if (StructValues.contains(inputs[i])) {
       Value *Idx[2];
-      Idx[0] = Constant::getNullValue(Type::getInt32Ty(header->getContext()));
+      Idx[0] =
+          Constant::getNullValue(Type::getInt32Ty(header->getContext()),
+                                 &newFunction->getParent()->getDataLayout());
       Idx[1] = ConstantInt::get(Type::getInt32Ty(header->getContext()), aggIdx);
       GetElementPtrInst *GEP = GetElementPtrInst::Create(
           StructArgTy, AggArg, Idx, "gep_" + inputs[i]->getName(), newFuncRoot);
@@ -1787,7 +1789,9 @@ void CodeExtractor::emitFunctionBody(
       assert(AggArg && "Number of aggregate output arguments should match "
                        "the number of defined values");
       Value *Idx[2];
-      Idx[0] = Constant::getNullValue(Type::getInt32Ty(Context));
+      Idx[0] =
+          Constant::getNullValue(Type::getInt32Ty(Context),
+                                 &newFunction->getParent()->getDataLayout());
       Idx[1] = ConstantInt::get(Type::getInt32Ty(Context), AggIdx);
       GetElementPtrInst *GEP = GetElementPtrInst::Create(
           StructArgTy, AggArg, Idx, "gep_" + Output->getName(), InsertPt);
@@ -1879,7 +1883,9 @@ CallInst *CodeExtractor::emitReplacerCall(
         continue;
 
       Value *Idx[2];
-      Idx[0] = Constant::getNullValue(Type::getInt32Ty(Context));
+      Idx[0] =
+          Constant::getNullValue(Type::getInt32Ty(Context),
+                                 &newFunction->getParent()->getDataLayout());
       Idx[1] = ConstantInt::get(Type::getInt32Ty(Context), AggIdx);
       GetElementPtrInst *GEP = GetElementPtrInst::Create(
           StructArgTy, Struct, Idx, "gep_" + input->getName());
@@ -1923,7 +1929,9 @@ CallInst *CodeExtractor::emitReplacerCall(
     Value *Output = nullptr;
     if (StructValues.contains(outputs[i])) {
       Value *Idx[2];
-      Idx[0] = Constant::getNullValue(Type::getInt32Ty(Context));
+      Idx[0] =
+          Constant::getNullValue(Type::getInt32Ty(Context),
+                                 &newFunction->getParent()->getDataLayout());
       Idx[1] = ConstantInt::get(Type::getInt32Ty(Context), AggIdx);
       GetElementPtrInst *GEP = GetElementPtrInst::Create(
           StructArgTy, Struct, Idx, "gep_reload_" + outputs[i]->getName());
@@ -1942,7 +1950,7 @@ CallInst *CodeExtractor::emitReplacerCall(
 
   // Now we can emit a switch statement using the call as a value.
   SwitchInst *TheSwitch =
-      SwitchInst::Create(Constant::getNullValue(Type::getInt16Ty(Context)),
+      SwitchInst::Create(Constant::getNullValue(Type::getInt16Ty(Context), &DL),
                          codeReplacer, 0, codeReplacer);
   for (auto P : enumerate(ExtractedFuncRetVals)) {
     BasicBlock *OldTarget = P.value();
@@ -1973,7 +1981,7 @@ CallInst *CodeExtractor::emitReplacerCall(
     } else {
       // Otherwise we must have code extracted an unwind or something, just
       // return whatever we want.
-      ReturnInst::Create(Context, Constant::getNullValue(OldFnRetTy),
+      ReturnInst::Create(Context, Constant::getNullValue(OldFnRetTy, &DL),
                          TheSwitch->getIterator());
     }
 
diff --git a/llvm/lib/Transforms/Utils/FunctionImportUtils.cpp b/llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
index d31154fcf085d..1222bd97e5873 100644
--- a/llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
+++ b/llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
@@ -301,7 +301,8 @@ void FunctionImportGlobalProcessing::processGlobalForThinLTO(GlobalValue &GV) {
         // ignore them when computing import. We do not export references
         // of writeonly object. See computeImportForReferencedGlobals
         if (ImportIndex.isWriteOnly(GVS))
-          V->setInitializer(Constant::getNullValue(V->getValueType()));
+          V->setInitializer(Constant::getNullValue(
+              V->getValueType(), &GV.getParent()->getDataLayout()));
       }
     }
   }
diff --git a/llvm/lib/Transforms/Utils/LowerGlobalDtors.cpp b/llvm/lib/Transforms/Utils/LowerGlobalDtors.cpp
index df3a2a94b7ddb..4f00c6795e02d 100644
--- a/llvm/lib/Transforms/Utils/LowerGlobalDtors.cpp
+++ b/llvm/lib/Transforms/Utils/LowerGlobalDtors.cpp
@@ -208,8 +208,9 @@ static bool runImpl(Module &M) {
       Value *Null = ConstantPointerNull::get(VoidStar);
       Value *Args[] = {CallDtors, Null, DsoHandle};
       Value *Res = CallInst::Create(AtExit, Args, "call", EntryBB);
-      Value *Cmp = new ICmpInst(EntryBB, ICmpInst::ICMP_NE, Res,
-                                Constant::getNullValue(Res->getType()));
+      Value *Cmp = new ICmpInst(
+          EntryBB, ICmpInst::ICMP_NE, Res,
+          Constant::getNullValue(Res->getType(), &M.getDataLayout()));
       BranchInst::Create(FailBB, RetBB, Cmp, EntryBB);
 
       // If `__cxa_atexit` hits out-of-memory, trap, so that we don't misbehave.
diff --git a/llvm/lib/Transforms/Utils/MemoryTaggingSupport.cpp b/llvm/lib/Transforms/Utils/MemoryTaggingSupport.cpp
index e9def70d24d9e..30c5152d9d231 100644
--- a/llvm/lib/Transforms/Utils/MemoryTaggingSupport.cpp
+++ b/llvm/lib/Transforms/Utils/MemoryTaggingSupport.cpp
@@ -256,9 +256,10 @@ Value *getFP(IRBuilder<> &IRB) {
   Function *F = IRB.GetInsertBlock()->getParent();
   Module *M = F->getParent();
   return IRB.CreatePtrToInt(
-      IRB.CreateIntrinsic(Intrinsic::frameaddress,
-                          IRB.getPtrTy(M->getDataLayout().getAllocaAddrSpace()),
-                          {Constant::getNullValue(IRB.getInt32Ty())}),
+      IRB.CreateIntrinsic(
+          Intrinsic::frameaddress,
+          IRB.getPtrTy(M->getDataLayout().getAllocaAddrSpace()),
+          {Constant::getNullValue(IRB.getInt32Ty(), &F->getDataLayout())}),
       IRB.getIntPtrTy(M->getDataLayout()));
 }
 
diff --git a/llvm/lib/Transforms/Utils/ModuleUtils.cpp b/llvm/lib/Transforms/Utils/ModuleUtils.cpp
index df1d1568c8ffc..4c94c4756f177 100644
--- a/llvm/lib/Transforms/Utils/ModuleUtils.cpp
+++ b/llvm/lib/Transforms/Utils/ModuleUtils.cpp
@@ -56,7 +56,7 @@ static void appendToGlobalArray(StringRef ArrayName, Module &M, Function *F,
   CSVals[0] = IRB.getInt32(Priority);
   CSVals[1] = F;
   CSVals[2] = Data ? ConstantExpr::getPointerCast(Data, IRB.getPtrTy())
-                   : Constant::getNullValue(IRB.getPtrTy());
+                   : Constant::getNullValue(IRB.getPtrTy(), &M.getDataLayout());
   Constant *RuntimeCtorInit =
       ConstantStruct::get(EltTy, ArrayRef(CSVals, EltTy->getNumElements()));
 
diff --git a/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp b/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
index ef668e575f3ea..b7d6cc803e151 100644
--- a/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
+++ b/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
@@ -489,8 +489,9 @@ struct PromoteMem2Reg {
 static void addAssumeNonNull(AssumptionCache *AC, LoadInst *LI) {
   Function *AssumeIntrinsic =
       Intrinsic::getOrInsertDeclaration(LI->getModule(), Intrinsic::assume);
-  ICmpInst *LoadNotNull = new ICmpInst(ICmpInst::ICMP_NE, LI,
-                                       Constant::getNullValue(LI->getType()));
+  ICmpInst *LoadNotNull = new ICmpInst(
+      ICmpInst::ICMP_NE, LI,
+      Constant::getNullValue(LI->getType(), &LI->getModule()->getDataLayout()));
   LoadNotNull->insertAfter(LI->getIterator());
   CallInst *CI = CallInst::Create(AssumeIntrinsic, {LoadNotNull});
   CI->insertAfter(LoadNotNull->getIterator());
diff --git a/llvm/lib/Transforms/Utils/SCCPSolver.cpp b/llvm/lib/Transforms/Utils/SCCPSolver.cpp
index 0ac99413a2cf8..36961d9547507 100644
--- a/llvm/lib/Transforms/Utils/SCCPSolver.cpp
+++ b/llvm/lib/Transforms/Utils/SCCPSolver.cpp
@@ -617,7 +617,7 @@ class SCCPInstVisitor : public InstVisitor<SCCPInstVisitor> {
   bool markNotConstant(ValueLatticeElement &IV, Value *V, Constant *C);
 
   bool markNotNull(ValueLatticeElement &IV, Value *V) {
-    return markNotConstant(IV, V, Constant::getNullValue(V->getType()));
+    return markNotConstant(IV, V, Constant::getNullValue(V->getType(), &DL));
   }
 
   /// markConstantRange - Mark the object as constant range with \p CR. If the
@@ -973,7 +973,8 @@ class SCCPInstVisitor : public InstVisitor<SCCPInstVisitor> {
         return ValueLatticeElement::getRange(*Range);
     }
     if (A->hasNonNullAttr())
-      return ValueLatticeElement::getNot(Constant::getNullValue(A->getType()));
+      return ValueLatticeElement::getNot(
+          Constant::getNullValue(A->getType(), &DL));
     // Assume nothing about the incoming arguments without attributes.
     return ValueLatticeElement::getOverdefined();
   }
diff --git a/llvm/lib/Transforms/Utils/SanitizerStats.cpp b/llvm/lib/Transforms/Utils/SanitizerStats.cpp
index f4a45cb2edeb2..867c7e2ce4533 100644
--- a/llvm/lib/Transforms/Utils/SanitizerStats.cpp
+++ b/llvm/lib/Transforms/Utils/SanitizerStats.cpp
@@ -49,7 +49,7 @@ void SanitizerStatReport::create(IRBuilder<> &B, SanitizerStatKind SK) {
   const auto &DL = M->getDataLayout();
   Inits.push_back(ConstantArray::get(
       StatTy,
-      {Constant::getNullValue(PtrTy),
+      {Constant::getNullValue(PtrTy, &DL),
        ConstantExpr::getIntToPtr(
            ConstantInt::get(IntPtrTy, uint64_t(SK) << (IntPtrTy->getBitWidth() -
                                                        kSanitizerStatKindBits)),
@@ -85,7 +85,7 @@ void SanitizerStatReport::finish() {
   auto NewModuleStatsGV = new GlobalVariable(
       *M, makeModuleStatsTy(), false, GlobalValue::InternalLinkage,
       ConstantStruct::getAnon(
-          {Constant::getNullValue(Int8PtrTy),
+          {Constant::getNullValue(Int8PtrTy, &DL),
            ConstantInt::get(Int32Ty, Inits.size()),
            ConstantArray::get(makeModuleStatsArrayTy(), Inits, &DL)},
           /*Packed=*/false, &DL));
diff --git a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
index 5dd388e95accb..de0f447e9dbb2 100644
--- a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
+++ b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
@@ -243,7 +243,8 @@ Value *SCEVExpander::InsertNoopCastOfTo(Value *V, Type *Ty) {
   if (Op == Instruction::IntToPtr) {
     auto *PtrTy = cast<PointerType>(Ty);
     if (DL.isNonIntegralPointerType(PtrTy))
-      return Builder.CreatePtrAdd(Constant::getNullValue(PtrTy), V, "scevgep");
+      return Builder.CreatePtrAdd(Constant::getNullValue(PtrTy, &DL), V,
+                                  "scevgep");
   }
   // Short-circuit unnecessary bitcasts.
   if (Op == Instruction::BitCast) {
@@ -658,8 +659,8 @@ Value *SCEVExpander::visitMulExpr(const SCEVMulExpr *S) {
       Prod = ExpandOpBinPowN();
     } else if (I->second->isAllOnesValue()) {
       // Instead of doing a multiply by negative one, just do a negate.
-      Prod = InsertBinop(Instruction::Sub, Constant::getNullValue(Ty), Prod,
-                         SCEV::FlagAnyWrap, /*IsSafeToHoist*/ true);
+      Prod = InsertBinop(Instruction::Sub, Constant::getNullValue(Ty, &DL),
+                         Prod, SCEV::FlagAnyWrap, /*IsSafeToHoist*/ true);
       ++I;
     } else {
       // A simple mul.
@@ -1405,7 +1406,7 @@ Value *SCEVExpander::visitAddRecExpr(const SCEVAddRecExpr *S) {
         rememberInstruction(Add);
         CanonicalIV->addIncoming(Add, HP);
       } else {
-        CanonicalIV->addIncoming(Constant::getNullValue(Ty), HP);
+        CanonicalIV->addIncoming(Constant::getNullValue(Ty, &DL), HP);
       }
     }
   }
@@ -1684,8 +1685,9 @@ Value *SCEVExpander::expand(const SCEV *S) {
       if (auto *NNI = dyn_cast<PossiblyNonNegInst>(I)) {
         auto *Src = NNI->getOperand(0);
         if (isImpliedByDomCondition(ICmpInst::ICMP_SGE, Src,
-                                    Constant::getNullValue(Src->getType()), I,
-                                    DL).value_or(false))
+                                    Constant::getNullValue(Src->getType(), &DL),
+                                    I, DL)
+                .value_or(false))
           NNI->setNonNeg(true);
       }
     }
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index ad8a332e7cb40..0338b7dd452db 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -6649,7 +6649,8 @@ static Value *foldSwitchToSelect(const SwitchCaseResultVectorTy &ResultVector,
           Condition = Builder.CreateSub(Condition, MinCaseVal);
         Value *And = Builder.CreateAnd(Condition, ~BitMask, "switch.and");
         Value *Cmp = Builder.CreateICmpEQ(
-            And, Constant::getNullValue(And->getType()), "switch.selectcmp");
+            And, Constant::getNullValue(And->getType(), &DL),
+            "switch.selectcmp");
         Value *Ret =
             Builder.CreateSelect(Cmp, ResultVector[0].first, DefaultResult);
         if (auto *SI = dyn_cast<SelectInst>(Ret); SI && HasBranchWeights) {
diff --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
index c324319bf614d..8bd3ae2576483 100644
--- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -480,7 +480,7 @@ static Value* memChrToCharCompare(CallInst *CI, Value *NBytes,
     Cmp = B.CreateLogicalAnd(And, Cmp);
   }
 
-  Value *NullPtr = Constant::getNullValue(CI->getType());
+  Value *NullPtr = Constant::getNullValue(CI->getType(), &DL);
   return B.CreateSelect(Cmp, Src, NullPtr);
 }
 
@@ -517,7 +517,7 @@ Value *LibCallSimplifier::optimizeStrChr(CallInst *CI, IRBuilderBase &B) {
   }
 
   if (CharC->isZero()) {
-    Value *NullPtr = Constant::getNullValue(CI->getType());
+    Value *NullPtr = Constant::getNullValue(CI->getType(), &DL);
     if (isOnlyUsedInEqualityComparison(CI, NullPtr))
       // Pre-empt the transformation to strlen below and fold
       // strchr(A, '\0') == null to false.
@@ -540,7 +540,7 @@ Value *LibCallSimplifier::optimizeStrChr(CallInst *CI, IRBuilderBase &B) {
                  ? Str.size()
                  : Str.find(CharC->getSExtValue());
   if (I == StringRef::npos) // Didn't find the char.  strchr returns null.
-    return Constant::getNullValue(CI->getType());
+    return Constant::getNullValue(CI->getType(), &DL);
 
   // strchr(s+n,c)  -> gep(s+n+i,c)
   return B.CreateInBoundsGEP(B.getInt8Ty(), SrcStr, B.getInt64(I), "strchr");
@@ -1088,13 +1088,13 @@ Value *LibCallSimplifier::optimizeStrPBrk(CallInst *CI, IRBuilderBase &B) {
   // strpbrk(s, "") -> nullptr
   // strpbrk("", s) -> nullptr
   if ((HasS1 && S1.empty()) || (HasS2 && S2.empty()))
-    return Constant::getNullValue(CI->getType());
+    return Constant::getNullValue(CI->getType(), &DL);
 
   // Constant folding.
   if (HasS1 && HasS2) {
     size_t I = S1.find_first_of(S2);
     if (I == StringRef::npos) // No match.
-      return Constant::getNullValue(CI->getType());
+      return Constant::getNullValue(CI->getType(), &DL);
 
     return B.CreateInBoundsGEP(B.getInt8Ty(), CI->getArgOperand(0),
                                B.getInt64(I), "strpbrk");
@@ -1127,7 +1127,7 @@ Value *LibCallSimplifier::optimizeStrSpn(CallInst *CI, IRBuilderBase &B) {
   // strspn(s, "") -> 0
   // strspn("", s) -> 0
   if ((HasS1 && S1.empty()) || (HasS2 && S2.empty()))
-    return Constant::getNullValue(CI->getType());
+    return Constant::getNullValue(CI->getType(), &DL);
 
   // Constant folding.
   if (HasS1 && HasS2) {
@@ -1147,7 +1147,7 @@ Value *LibCallSimplifier::optimizeStrCSpn(CallInst *CI, IRBuilderBase &B) {
 
   // strcspn("", s) -> 0
   if (HasS1 && S1.empty())
-    return Constant::getNullValue(CI->getType());
+    return Constant::getNullValue(CI->getType(), &DL);
 
   // Constant folding.
   if (HasS1 && HasS2) {
@@ -1202,7 +1202,7 @@ Value *LibCallSimplifier::optimizeStrStr(CallInst *CI, IRBuilderBase &B) {
     size_t Offset = SearchStr.find(ToFindStr);
 
     if (Offset == StringRef::npos) // strstr("foo", "bar") -> null
-      return Constant::getNullValue(CI->getType());
+      return Constant::getNullValue(CI->getType(), &DL);
 
     // strstr("abcd", "bc") -> gep((char*)"abcd", 1)
     return B.CreateConstInBoundsGEP1_64(B.getInt8Ty(), CI->getArgOperand(0),
@@ -1224,7 +1224,7 @@ Value *LibCallSimplifier::optimizeMemRChr(CallInst *CI, IRBuilderBase &B) {
   annotateNonNullAndDereferenceable(CI, 0, Size, DL);
   Value *CharVal = CI->getArgOperand(1);
   ConstantInt *LenC = dyn_cast<ConstantInt>(Size);
-  Value *NullPtr = Constant::getNullValue(CI->getType());
+  Value *NullPtr = Constant::getNullValue(CI->getType(), &DL);
 
   if (LenC) {
     if (LenC->isZero())
@@ -1319,7 +1319,7 @@ Value *LibCallSimplifier::optimizeMemChr(CallInst *CI, IRBuilderBase &B) {
   Value *CharVal = CI->getArgOperand(1);
   ConstantInt *CharC = dyn_cast<ConstantInt>(CharVal);
   ConstantInt *LenC = dyn_cast<ConstantInt>(Size);
-  Value *NullPtr = Constant::getNullValue(CI->getType());
+  Value *NullPtr = Constant::getNullValue(CI->getType(), &DL);
 
   // memchr(x, y, 0) -> null
   if (LenC) {
@@ -1505,7 +1505,7 @@ static Value *optimizeMemCmpVarSize(CallInst *CI, Value *LHS, Value *RHS,
                                     Value *Size, bool StrNCmp,
                                     IRBuilderBase &B, const DataLayout &DL) {
   if (LHS == RHS) // memcmp(s,s,x) -> 0
-    return Constant::getNullValue(CI->getType());
+    return Constant::getNullValue(CI->getType(), &DL);
 
   StringRef LStr, RStr;
   if (!getConstantStringInfo(LHS, LStr, /*TrimAtNul=*/false) ||
@@ -1547,7 +1547,7 @@ static Value *optimizeMemCmpConstantSize(CallInst *CI, Value *LHS, Value *RHS,
                                          uint64_t Len, IRBuilderBase &B,
                                          const DataLayout &DL) {
   if (Len == 0) // memcmp(s1,s2,0) -> 0
-    return Constant::getNullValue(CI->getType());
+    return Constant::getNullValue(CI->getType(), &DL);
 
   // memcmp(S1,S2,1) -> *(unsigned char*)LHS - *(unsigned char*)RHS
   if (Len == 1) {
@@ -1655,7 +1655,7 @@ Value *LibCallSimplifier::optimizeMemCCpy(CallInst *CI, IRBuilderBase &B) {
   // memccpy(d, s, c, 0) -> nullptr
   if (N) {
     if (N->isNullValue())
-      return Constant::getNullValue(CI->getType());
+      return Constant::getNullValue(CI->getType(), &DL);
     if (!getConstantStringInfo(Src, SrcStr, /*TrimAtNul=*/false) ||
         // TODO: Handle zeroinitializer.
         !StopChar)
@@ -1670,7 +1670,7 @@ Value *LibCallSimplifier::optimizeMemCCpy(CallInst *CI, IRBuilderBase &B) {
     if (N->getZExtValue() <= SrcStr.size()) {
       copyFlags(*CI, B.CreateMemCpy(Dst, Align(1), Src, Align(1),
                                     CI->getArgOperand(3)));
-      return Constant::getNullValue(CI->getType());
+      return Constant::getNullValue(CI->getType(), &DL);
     }
     return nullptr;
   }
@@ -1681,7 +1681,7 @@ Value *LibCallSimplifier::optimizeMemCCpy(CallInst *CI, IRBuilderBase &B) {
   copyFlags(*CI, B.CreateMemCpy(Dst, Align(1), Src, Align(1), NewN));
   return Pos + 1 <= N->getZExtValue()
              ? B.CreateInBoundsGEP(B.getInt8Ty(), Dst, NewN)
-             : Constant::getNullValue(CI->getType());
+             : Constant::getNullValue(CI->getType(), &DL);
 }
 
 Value *LibCallSimplifier::optimizeMemPCpy(CallInst *CI, IRBuilderBase &B) {
@@ -3207,7 +3207,7 @@ Value *LibCallSimplifier::optimizeFFS(CallInst *CI, IRBuilderBase &B) {
   V = B.CreateAdd(V, ConstantInt::get(V->getType(), 1));
   V = B.CreateIntCast(V, RetType, false);
 
-  Value *Cond = B.CreateICmpNE(Op, Constant::getNullValue(ArgType));
+  Value *Cond = B.CreateICmpNE(Op, Constant::getNullValue(ArgType, &DL));
   return B.CreateSelect(Cond, V, ConstantInt::get(RetType, 0));
 }
 
diff --git a/llvm/lib/Transforms/Vectorize/LoopIdiomVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopIdiomVectorize.cpp
index cca7a3f5ef007..1c2f5d6227478 100644
--- a/llvm/lib/Transforms/Vectorize/LoopIdiomVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopIdiomVectorize.cpp
@@ -1329,7 +1329,7 @@ Value *LoopIdiomVectorize::expandFindFirstByte(
   PredSearch = Builder.CreateAnd(PredVF, PredSearch, "search_masked");
   Value *LoadSearch = Builder.CreateMaskedLoad(
       CharVTy, Search, Align(1), PredSearch, Passthru, "search_load_vec");
-  Value *MatchInit = Constant::getNullValue(PredVTy);
+  Value *MatchInit = Constant::getNullValue(PredVTy, DL);
   Builder.CreateBr(BB2);
   DTU.applyUpdates({{DominatorTree::Insert, BB1, BB2}});
 
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 361caf8b77855..167e2c9abc88b 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -14634,7 +14634,7 @@ class BoUpSLP::ShuffleCostEstimator : public BaseShuffleAnalysis {
         ExtraCost += GetNodeMinBWAffectedCost(*E, E->getVectorFactor()) +
                      GetNodeMinBWAffectedCost(*E2, E2->getVectorFactor());
       }
-      V1 = Constant::getNullValue(getWidenedType(ScalarTy, CommonVF));
+      V1 = Constant::getNullValue(getWidenedType(ScalarTy, CommonVF), R.DL);
       V2 = getAllOnesValue(*R.DL, getWidenedType(ScalarTy, CommonVF));
     } else if (!V1 && P2.isNull()) {
       // Shuffle single entry node.
@@ -14661,7 +14661,7 @@ class BoUpSLP::ShuffleCostEstimator : public BaseShuffleAnalysis {
         std::iota(CommonMask.begin(), CommonMask.end(), 0);
       }
       ExtraCost += GetNodeMinBWAffectedCost(*E, CommonVF);
-      V1 = Constant::getNullValue(getWidenedType(ScalarTy, CommonVF));
+      V1 = Constant::getNullValue(getWidenedType(ScalarTy, CommonVF), R.DL);
       // Not identity/broadcast? Try to see if the original vector is better.
       if (!E->ReorderIndices.empty() && CommonVF == E->ReorderIndices.size() &&
           CommonVF == CommonMask.size() &&
@@ -14706,7 +14706,7 @@ class BoUpSLP::ShuffleCostEstimator : public BaseShuffleAnalysis {
         CommonVF = VF;
       }
       ExtraCost += GetValueMinBWAffectedCost(V1);
-      V1 = Constant::getNullValue(getWidenedType(ScalarTy, CommonVF));
+      V1 = Constant::getNullValue(getWidenedType(ScalarTy, CommonVF), R.DL);
       ExtraCost += GetNodeMinBWAffectedCost(
           *E2, std::min(CommonVF, E2->getVectorFactor()));
       V2 = getAllOnesValue(*R.DL, getWidenedType(ScalarTy, CommonVF));
@@ -14735,7 +14735,7 @@ class BoUpSLP::ShuffleCostEstimator : public BaseShuffleAnalysis {
       }
       ExtraCost += GetNodeMinBWAffectedCost(
           *E1, std::min(CommonVF, E1->getVectorFactor()));
-      V1 = Constant::getNullValue(getWidenedType(ScalarTy, CommonVF));
+      V1 = Constant::getNullValue(getWidenedType(ScalarTy, CommonVF), R.DL);
       ExtraCost += GetValueMinBWAffectedCost(V2);
       V2 = getAllOnesValue(*R.DL, getWidenedType(ScalarTy, CommonVF));
     } else {
@@ -14750,17 +14750,17 @@ class BoUpSLP::ShuffleCostEstimator : public BaseShuffleAnalysis {
       ExtraCost +=
           GetValueMinBWAffectedCost(V1) + GetValueMinBWAffectedCost(V2);
       if (V1->getType() != V2->getType()) {
-        V1 = Constant::getNullValue(getWidenedType(ScalarTy, CommonVF));
+        V1 = Constant::getNullValue(getWidenedType(ScalarTy, CommonVF), R.DL);
         V2 = getAllOnesValue(*R.DL, getWidenedType(ScalarTy, CommonVF));
       } else {
         if (cast<VectorType>(V1->getType())->getElementType() != ScalarTy)
-          V1 = Constant::getNullValue(getWidenedType(ScalarTy, CommonVF));
+          V1 = Constant::getNullValue(getWidenedType(ScalarTy, CommonVF), R.DL);
         if (cast<VectorType>(V2->getType())->getElementType() != ScalarTy)
           V2 = getAllOnesValue(*R.DL, getWidenedType(ScalarTy, CommonVF));
       }
     }
-    InVectors.front() =
-        Constant::getNullValue(getWidenedType(ScalarTy, CommonMask.size()));
+    InVectors.front() = Constant::getNullValue(
+        getWidenedType(ScalarTy, CommonMask.size()), R.DL);
     if (InVectors.size() == 2)
       InVectors.pop_back();
     return ExtraCost + BaseShuffleAnalysis::createShuffle<InstructionCost>(
@@ -14891,8 +14891,8 @@ class BoUpSLP::ShuffleCostEstimator : public BaseShuffleAnalysis {
     SameNodesEstimated = false;
     if (NumParts != 1 && UniqueBases.size() != 1) {
       UseVecBaseAsInput = true;
-      VecBase =
-          Constant::getNullValue(getWidenedType(ScalarTy, CommonMask.size()));
+      VecBase = Constant::getNullValue(
+          getWidenedType(ScalarTy, CommonMask.size()), R.DL);
     }
     return VecBase;
   }
@@ -15037,7 +15037,7 @@ class BoUpSLP::ShuffleCostEstimator : public BaseShuffleAnalysis {
           Vals.push_back(UndefValue::get(ScalarTy));
           continue;
         }
-        Vals.push_back(Constant::getNullValue(ScalarTy));
+        Vals.push_back(Constant::getNullValue(ScalarTy, R.DL));
       }
       if (auto *VecTy = dyn_cast<FixedVectorType>(VLScalarTy)) {
         assert(SLPReVec && "FixedVectorType is not expected.");
@@ -22362,7 +22362,8 @@ Value *BoUpSLP::vectorizeTree(
       // Replace conditions of the poisoning logical ops with the non-poison
       // constant value.
       for (SelectInst *SI : LogicalOpSelects)
-        SI->setCondition(Constant::getNullValue(SI->getCondition()->getType()));
+        SI->setCondition(
+            Constant::getNullValue(SI->getCondition()->getType(), DL));
     }
   }
   // Retain to-be-deleted instructions for some debug-info bookkeeping and alias
@@ -26890,7 +26891,7 @@ class HorizontalReduction {
           LLVM_DEBUG(dbgs()
                      << "SLP: Xor " << Cnt << "of " << Vec << ". (HorRdx)\n");
           if (Cnt % 2 == 0)
-            Vec = Constant::getNullValue(Vec->getType());
+            Vec = Constant::getNullValue(Vec->getType(), &DL);
           break;
         }
         case RecurKind::FAdd: {
diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
index 9a3cd353dc982..c730e5703c9e5 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
@@ -2564,8 +2564,12 @@ void VPScalarIVStepsRecipe::execute(VPTransformState &State) {
     StartLane = State.Lane->getKnownLane();
     EndLane = StartLane + 1;
   }
-  Value *StartIdx0 = getStartIndex() ? State.get(getStartIndex(), true)
-                                     : Constant::getNullValue(BaseIVTy);
+  Value *StartIdx0 =
+      getStartIndex()
+          ? State.get(getStartIndex(), true)
+          : Constant::getNullValue(
+                BaseIVTy,
+                &State.Builder.GetInsertBlock()->getModule()->getDataLayout());
 
   for (unsigned Lane = StartLane; Lane < EndLane; ++Lane) {
     // It is okay if the induction variable type cannot hold the lane number,
diff --git a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
index 42e615c1d80b1..9c922086cf8d7 100644
--- a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
+++ b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
@@ -1662,8 +1662,8 @@ bool VectorCombine::foldSelectsFromBitcast(Instruction &I) {
         InsertPt = std::next(CondInst->getIterator());
 
     Builder.SetInsertPoint(InsertPt);
-    Value *VecSel =
-        Builder.CreateSelect(Cond, SrcVec, Constant::getNullValue(SrcVecTy));
+    Value *VecSel = Builder.CreateSelect(Cond, SrcVec,
+                                         Constant::getNullValue(SrcVecTy, DL));
     Value *NewBC = Builder.CreateBitCast(VecSel, DstVecTy);
 
     // Replace each scalar select with an extract from the new bitcast.



More information about the llvm-branch-commits mailing list