[clang] [llvm] [LLVM][IR] Add native vector support to ConstantInt & ConstantFP. (PR #74502)
@@ -98,6 +99,13 @@ class ConstantInt final : public ConstantData { /// value. Otherwise return a ConstantInt for the given value. static Constant *get(Type *Ty, uint64_t V, bool IsSigned = false); + /// WARNING: Incomplete support, do not use. These methods exist for early + /// prototyping, for most use cases ConstantInt::get() should be used. + /// Return a ConstantInt with a splat of the given value. + static ConstantInt *getSplat(LLVMContext , ElementCount EC, + const APInt ); + static ConstantInt *getSplat(const VectorType *Ty, const APInt ); paulwalker-arm wrote: I've moved the textual IR side of things to https://github.com/llvm/llvm-project/pull/74620 following the suggestion to have `splat(x)` be synonymous with `ConstantInt/FP::get()`. https://github.com/llvm/llvm-project/pull/74502 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [LLVM][IR] Add native vector support to ConstantInt & ConstantFP. (PR #74502)
@@ -343,7 +343,7 @@ static bool verifyTripCount(Value *RHS, Loop *L, // If the RHS of the compare is equal to the backedge taken count we need // to add one to get the trip count. if (SCEVRHS == BackedgeTCExt || SCEVRHS == BackedgeTakenCount) { - ConstantInt *One = ConstantInt::get(ConstantRHS->getType(), 1); + ConstantInt *One = ConstantInt::get(ConstantRHS->getIntegerType(), 1); nikic wrote: I don't really follow here. Even if you rename the overload on ConstantInt, there will still be the method inherited from `Value::getType()`, and using that method here should work (and be forward-compatible with vector ConstantInt), because `ConstantInt::get` doesn't actually require that the argument is an IntegerType. https://github.com/llvm/llvm-project/pull/74502 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [LLVM][IR] Add native vector support to ConstantInt & ConstantFP. (PR #74502)
@@ -136,7 +144,11 @@ class ConstantInt final : public ConstantData { inline const APInt () const { return Val; } /// getBitWidth - Return the bitwidth of this constant. - unsigned getBitWidth() const { return Val.getBitWidth(); } + unsigned getBitWidth() const { +assert(getType()->isIntegerTy() && + "Returning the bitwidth of a vector constant is not support!"); nikic wrote: IMHO this is not necessary. If the name were `getSizeInBits()` I would agree, but the term "bit width" implies that we're talking about scalar. We don't use the term "bit width" to refer to full size of a vector. https://github.com/llvm/llvm-project/pull/74502 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [LLVM][IR] Add native vector support to ConstantInt & ConstantFP. (PR #74502)
@@ -98,6 +99,13 @@ class ConstantInt final : public ConstantData { /// value. Otherwise return a ConstantInt for the given value. static Constant *get(Type *Ty, uint64_t V, bool IsSigned = false); + /// WARNING: Incomplete support, do not use. These methods exist for early + /// prototyping, for most use cases ConstantInt::get() should be used. + /// Return a ConstantInt with a splat of the given value. + static ConstantInt *getSplat(LLVMContext , ElementCount EC, + const APInt ); + static ConstantInt *getSplat(const VectorType *Ty, const APInt ); nikic wrote: I think this isn't the right way to phase in the change. I think the `splat` syntax should just return whatever `ConstantVector::getSplat()` produces, and what that produces can be controlled by the opt flags you have introduced. That means that the splat syntax becomes usable right away as a short-hand for producing the representations we currently use, and will switch to producing plain ConstantInt/ConstantFP once the flag is flipped (or in tests that explicitly flip it). https://github.com/llvm/llvm-project/pull/74502 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [LLVM][IR] Add native vector support to ConstantInt & ConstantFP. (PR #74502)
@@ -343,7 +343,7 @@ static bool verifyTripCount(Value *RHS, Loop *L, // If the RHS of the compare is equal to the backedge taken count we need // to add one to get the trip count. if (SCEVRHS == BackedgeTCExt || SCEVRHS == BackedgeTakenCount) { - ConstantInt *One = ConstantInt::get(ConstantRHS->getType(), 1); + ConstantInt *One = ConstantInt::get(ConstantRHS->getIntegerType(), 1); paulwalker-arm wrote: Much the same reason as with `getBitWidth()` but the need for immediate change is greater so I renamed this method so changes to existing code paths are minimal whilst still providing a route to trigger asserts once testing is expanded. I did consider just removing the method and adding the necessary casts but figured somebody went to the trouble of adding the override in the first place so I maintained this but under a modified name. Do you think the shorthand is not worth it? https://github.com/llvm/llvm-project/pull/74502 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [LLVM][IR] Add native vector support to ConstantInt & ConstantFP. (PR #74502)
@@ -136,7 +144,11 @@ class ConstantInt final : public ConstantData { inline const APInt () const { return Val; } /// getBitWidth - Return the bitwidth of this constant. - unsigned getBitWidth() const { return Val.getBitWidth(); } + unsigned getBitWidth() const { +assert(getType()->isIntegerTy() && + "Returning the bitwidth of a vector constant is not support!"); paulwalker-arm wrote: Ultimately I think this should be more explicit, for example `getScalarBitWidth()`. For this patch though the need was tiny so I made this change purely to trigger asserts at this level when failure cases are hit once I start expanding the testing. https://github.com/llvm/llvm-project/pull/74502 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [LLVM][IR] Add native vector support to ConstantInt & ConstantFP. (PR #74502)
@@ -98,6 +99,13 @@ class ConstantInt final : public ConstantData { /// value. Otherwise return a ConstantInt for the given value. static Constant *get(Type *Ty, uint64_t V, bool IsSigned = false); + /// WARNING: Incomplete support, do not use. These methods exist for early + /// prototyping, for most use cases ConstantInt::get() should be used. + /// Return a ConstantInt with a splat of the given value. + static ConstantInt *getSplat(LLVMContext , ElementCount EC, + const APInt ); + static ConstantInt *getSplat(const VectorType *Ty, const APInt ); paulwalker-arm wrote: We're in a transition period and thus I need an absolute way to create a vector ConstantInt (e.g. when parsing ll files and bitcode). Today `ConstantInt::get()` returns other `Constant` types to represent splats and that must be maintained for correctness because there are many code paths for which a vector ConstantInt will break. https://github.com/llvm/llvm-project/pull/74502 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [LLVM][IR] Add native vector support to ConstantInt & ConstantFP. (PR #74502)
@@ -343,7 +343,7 @@ static bool verifyTripCount(Value *RHS, Loop *L, // If the RHS of the compare is equal to the backedge taken count we need // to add one to get the trip count. if (SCEVRHS == BackedgeTCExt || SCEVRHS == BackedgeTakenCount) { - ConstantInt *One = ConstantInt::get(ConstantRHS->getType(), 1); + ConstantInt *One = ConstantInt::get(ConstantRHS->getIntegerType(), 1); nikic wrote: Why are you changing usages like these? This code should work fine with `getType()`. https://github.com/llvm/llvm-project/pull/74502 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [LLVM][IR] Add native vector support to ConstantInt & ConstantFP. (PR #74502)
@@ -98,6 +99,13 @@ class ConstantInt final : public ConstantData { /// value. Otherwise return a ConstantInt for the given value. static Constant *get(Type *Ty, uint64_t V, bool IsSigned = false); + /// WARNING: Incomplete support, do not use. These methods exist for early + /// prototyping, for most use cases ConstantInt::get() should be used. + /// Return a ConstantInt with a splat of the given value. + static ConstantInt *getSplat(LLVMContext , ElementCount EC, + const APInt ); + static ConstantInt *getSplat(const VectorType *Ty, const APInt ); nikic wrote: I don't think these APIs should exist. `ConstantInt::get()` *already* supports creation of splats, they just aren't represented as `ConstantInt`s. https://github.com/llvm/llvm-project/pull/74502 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [LLVM][IR] Add native vector support to ConstantInt & ConstantFP. (PR #74502)
paulwalker-arm wrote: The PR contains a couple of commits that unless there's disagreement I'm tempted to land directly but have held off just in case there's any buyer remorse about extending ConstantInt/ConstantFP to cover vector types. For similar reasons I've not updated the LangRef as I don't really want people using the support until at least code generation works. https://github.com/llvm/llvm-project/pull/74502 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [LLVM][IR] Add native vector support to ConstantInt & ConstantFP. (PR #74502)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff 989e8f9d51e6945905b0e26148574c8e1fa88c84 d2ff1c7015265fb26d88b3f574d648f519ea531c -- clang/lib/CodeGen/CGBuiltin.cpp llvm/include/llvm/AsmParser/LLParser.h llvm/include/llvm/AsmParser/LLToken.h llvm/include/llvm/IR/Constants.h llvm/lib/Analysis/InstructionSimplify.cpp llvm/lib/AsmParser/LLLexer.cpp llvm/lib/AsmParser/LLParser.cpp llvm/lib/Bitcode/Reader/BitcodeReader.cpp llvm/lib/Bitcode/Writer/BitcodeWriter.cpp llvm/lib/IR/AsmWriter.cpp llvm/lib/IR/ConstantFold.cpp llvm/lib/IR/Constants.cpp llvm/lib/IR/LLVMContextImpl.cpp llvm/lib/IR/LLVMContextImpl.h llvm/lib/IR/Verifier.cpp llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp llvm/lib/Transforms/IPO/OpenMPOpt.cpp llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp llvm/lib/Transforms/Scalar/ConstantHoisting.cpp llvm/lib/Transforms/Scalar/LoopFlatten.cpp llvm/lib/Transforms/Utils/SimplifyCFG.cpp `` View the diff from clang-format here. ``diff diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 8dc828abf8..6444dc0c4d 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -226,8 +226,8 @@ static Value *MakeBinaryAtomicValue( llvm::Type *ValueType = Args[1]->getType(); Args[1] = EmitToInt(CGF, Args[1], T, IntType); - llvm::Value *Result = CGF.Builder.CreateAtomicRMW( - Kind, Args[0], Args[1], Ordering); + llvm::Value *Result = + CGF.Builder.CreateAtomicRMW(Kind, Args[0], Args[1], Ordering); return EmitFromInt(CGF, Result, T, ValueType); } @@ -372,8 +372,7 @@ Value *EmitAtomicCmpXchgForMSIntrin(CodeGenFunction , const CallExpr *E, // _Interlocked* operations in the future, we will have to remove the volatile // marker. auto *Result = CGF.Builder.CreateAtomicCmpXchg( - Destination, Comparand, Exchange, - SuccessOrdering, FailureOrdering); + Destination, Comparand, Exchange, SuccessOrdering, FailureOrdering); Result->setVolatile(true); return CGF.Builder.CreateExtractValue(Result, 0); } @@ -444,23 +443,20 @@ static Value *EmitAtomicIncrementValue(CodeGenFunction , const CallExpr *E, auto *IntTy = CGF.ConvertType(E->getType()); auto *Result = CGF.Builder.CreateAtomicRMW( - AtomicRMWInst::Add, - CGF.EmitScalarExpr(E->getArg(0)), - ConstantInt::get(IntTy, 1), - Ordering); + AtomicRMWInst::Add, CGF.EmitScalarExpr(E->getArg(0)), + ConstantInt::get(IntTy, 1), Ordering); return CGF.Builder.CreateAdd(Result, ConstantInt::get(IntTy, 1)); } -static Value *EmitAtomicDecrementValue(CodeGenFunction , const CallExpr *E, +static Value *EmitAtomicDecrementValue( +CodeGenFunction , const CallExpr *E, AtomicOrdering Ordering = AtomicOrdering::SequentiallyConsistent) { assert(E->getArg(0)->getType()->isPointerType()); auto *IntTy = CGF.ConvertType(E->getType()); auto *Result = CGF.Builder.CreateAtomicRMW( - AtomicRMWInst::Sub, - CGF.EmitScalarExpr(E->getArg(0)), - ConstantInt::get(IntTy, 1), - Ordering); + AtomicRMWInst::Sub, CGF.EmitScalarExpr(E->getArg(0)), + ConstantInt::get(IntTy, 1), Ordering); return CGF.Builder.CreateSub(Result, ConstantInt::get(IntTy, 1)); } @@ -4461,9 +4457,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, CharUnits StoreSize = getContext().getTypeSizeInChars(ElTy); llvm::Type *ITy = llvm::IntegerType::get(getLLVMContext(), StoreSize.getQuantity() * 8); -llvm::StoreInst *Store = - Builder.CreateAlignedStore(llvm::Constant::getNullValue(ITy), Ptr, - StoreSize); +llvm::StoreInst *Store = Builder.CreateAlignedStore( +llvm::Constant::getNullValue(ITy), Ptr, StoreSize); Store->setAtomic(llvm::AtomicOrdering::Release); return RValue::get(nullptr); } @@ -11903,9 +11898,9 @@ Value *CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID, case clang::AArch64::BI_InterlockedAdd: { Value *Arg0 = EmitScalarExpr(E->getArg(0)); Value *Arg1 = EmitScalarExpr(E->getArg(1)); -AtomicRMWInst *RMWI = Builder.CreateAtomicRMW( - AtomicRMWInst::Add, Arg0, Arg1, - llvm::AtomicOrdering::SequentiallyConsistent); +AtomicRMWInst *RMWI = +Builder.CreateAtomicRMW(AtomicRMWInst::Add, Arg0, Arg1, +llvm::AtomicOrdering::SequentiallyConsistent); return Builder.CreateAdd(RMWI, Arg1); } } diff --git a/llvm/include/llvm/AsmParser/LLParser.h b/llvm/include/llvm/AsmParser/LLParser.h index 38f6f08b8f..41054acf5e 100644 --- a/llvm/include/llvm/AsmParser/LLParser.h +++
[clang] [llvm] [LLVM][IR] Add native vector support to ConstantInt & ConstantFP. (PR #74502)
llvmbot wrote: @llvm/pr-subscribers-llvm-analysis @llvm/pr-subscribers-llvm-transforms Author: Paul Walker (paulwalker-arm) Changes [LLVM][IR] Add native vector support to ConstantInt ConstantFP. NOTE: For brevity the following takes about ConstantInt but everything extends to cover ConstantFP as well. Whilst ConstantInt::get() supports the creation of vectors whereby each lane has the same value, it achieves this via other constants: * ConstantVector for fixed-length vectors * ConstantExprs for scalable vectors ConstantExprs are being deprecated and ConstantVector is not space efficient for larger vector types. This patch introduces an alternative by allowing ConstantInt to natively support vector splats via the IR syntax: N x ty splat(ty imm) More specifically: * IR parsing is extended to support the new syntax. * ConstantInt gains the interface getSplat(). * LLVMContext is extended to map EC,APInt-ConstantInt. * BitCodeReader/Writer is extended to support vector types. Whilst this patch adds the base support, more work is required before it's production ready. For example, there's likely to be many places where isaConstantInt assumes a scalar type. Accordingly the default behaviour of ConstantInt::get() remains unchanged but a set of flag are added to allow wider testing and thus help with the migration: --use-constant-int-for-fixed-length-splat --use-constant-fp-for-fixed-length-splat --use-constant-int-for-scalable-splat --use-constant-fp-for-scalable-splat NOTE: No change is required to the bitcode format because types and values are handled separately. NOTE: Code generation doesn't work out-the-box but the issues look limited to calls to ConstantInt::getBitWidth() that will need to be ported. --- Patch is 41.22 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/74502.diff 22 Files Affected: - (modified) clang/lib/CodeGen/CGBuiltin.cpp (+4-3) - (modified) llvm/include/llvm/AsmParser/LLParser.h (+3-1) - (modified) llvm/include/llvm/AsmParser/LLToken.h (+1) - (modified) llvm/include/llvm/IR/Constants.h (+23-5) - (modified) llvm/lib/Analysis/InstructionSimplify.cpp (+1-1) - (modified) llvm/lib/AsmParser/LLLexer.cpp (+1) - (modified) llvm/lib/AsmParser/LLParser.cpp (+50-6) - (modified) llvm/lib/Bitcode/Reader/BitcodeReader.cpp (+41-29) - (modified) llvm/lib/Bitcode/Writer/BitcodeWriter.cpp (+3-3) - (modified) llvm/lib/IR/AsmWriter.cpp (+32-5) - (modified) llvm/lib/IR/ConstantFold.cpp (+1-1) - (modified) llvm/lib/IR/Constants.cpp (+92-1) - (modified) llvm/lib/IR/LLVMContextImpl.cpp (+2) - (modified) llvm/lib/IR/LLVMContextImpl.h (+4) - (modified) llvm/lib/IR/Verifier.cpp (+2-2) - (modified) llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp (+3-3) - (modified) llvm/lib/Transforms/IPO/OpenMPOpt.cpp (+8-7) - (modified) llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp (+2-2) - (modified) llvm/lib/Transforms/Scalar/ConstantHoisting.cpp (+3-3) - (modified) llvm/lib/Transforms/Scalar/LoopFlatten.cpp (+1-1) - (modified) llvm/lib/Transforms/Utils/SimplifyCFG.cpp (+4-4) - (added) llvm/test/Bitcode/constant-splat.ll (+53) ``diff diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 65d9862621061..8dc828abf8aec 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -3218,7 +3218,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, Value *AlignmentValue = EmitScalarExpr(E->getArg(1)); ConstantInt *AlignmentCI = cast(AlignmentValue); if (AlignmentCI->getValue().ugt(llvm::Value::MaximumAlignment)) - AlignmentCI = ConstantInt::get(AlignmentCI->getType(), + AlignmentCI = ConstantInt::get(AlignmentCI->getIntegerType(), llvm::Value::MaximumAlignment); emitAlignmentAssumption(PtrValue, Ptr, @@ -17010,7 +17010,7 @@ Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned BuiltinID, Value *Op1 = EmitScalarExpr(E->getArg(1)); ConstantInt *AlignmentCI = cast(Op0); if (AlignmentCI->getValue().ugt(llvm::Value::MaximumAlignment)) - AlignmentCI = ConstantInt::get(AlignmentCI->getType(), + AlignmentCI = ConstantInt::get(AlignmentCI->getIntegerType(), llvm::Value::MaximumAlignment); emitAlignmentAssumption(Op1, E->getArg(1), @@ -17248,7 +17248,8 @@ Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned BuiltinID, Op0, llvm::FixedVectorType::get(ConvertType(E->getType()), 2)); if (getTarget().isLittleEndian()) - Index = ConstantInt::get(Index->getType(), 1 - Index->getZExtValue()); + Index = + ConstantInt::get(Index->getIntegerType(), 1 - Index->getZExtValue()); return Builder.CreateExtractElement(Unpacked, Index); } diff --git a/llvm/include/llvm/AsmParser/LLParser.h b/llvm/include/llvm/AsmParser/LLParser.h index
[clang] [llvm] [LLVM][IR] Add native vector support to ConstantInt & ConstantFP. (PR #74502)
https://github.com/paulwalker-arm created https://github.com/llvm/llvm-project/pull/74502 [LLVM][IR] Add native vector support to ConstantInt & ConstantFP. NOTE: For brevity the following takes about ConstantInt but everything extends to cover ConstantFP as well. Whilst ConstantInt::get() supports the creation of vectors whereby each lane has the same value, it achieves this via other constants: * ConstantVector for fixed-length vectors * ConstantExprs for scalable vectors ConstantExprs are being deprecated and ConstantVector is not space efficient for larger vector types. This patch introduces an alternative by allowing ConstantInt to natively support vector splats via the IR syntax: splat(ty ) More specifically: * IR parsing is extended to support the new syntax. * ConstantInt gains the interface getSplat(). * LLVMContext is extended to map ->ConstantInt. * BitCodeReader/Writer is extended to support vector types. Whilst this patch adds the base support, more work is required before it's production ready. For example, there's likely to be many places where isa assumes a scalar type. Accordingly the default behaviour of ConstantInt::get() remains unchanged but a set of flag are added to allow wider testing and thus help with the migration: --use-constant-int-for-fixed-length-splat --use-constant-fp-for-fixed-length-splat --use-constant-int-for-scalable-splat --use-constant-fp-for-scalable-splat NOTE: No change is required to the bitcode format because types and values are handled separately. NOTE: Code generation doesn't work out-the-box but the issues look limited to calls to ConstantInt::getBitWidth() that will need to be ported. >From 4c999f2e134ffc0385ec18ecbf1a80a696b7d095 Mon Sep 17 00:00:00 2001 From: Paul Walker Date: Wed, 29 Nov 2023 14:45:06 + Subject: [PATCH 1/3] [NFC][LLVM][IR] Rename ConstantInt's getType() to getIntegerType(). Also adds an assert to ConstantInt::getBitWidth() to ensure it's only called for integer types. This will have no affect today but will aid with problem solving when ConstantInt is extended to support vector types. --- clang/lib/CodeGen/CGBuiltin.cpp | 7 --- llvm/include/llvm/IR/Constants.h | 12 +++- llvm/lib/Analysis/InstructionSimplify.cpp | 2 +- llvm/lib/IR/ConstantFold.cpp | 2 +- llvm/lib/IR/Verifier.cpp | 4 ++-- .../Hexagon/HexagonLoopIdiomRecognition.cpp | 6 +++--- llvm/lib/Transforms/IPO/OpenMPOpt.cpp | 15 --- .../InstCombine/InstCombineVectorOps.cpp | 4 ++-- llvm/lib/Transforms/Scalar/ConstantHoisting.cpp | 6 +++--- llvm/lib/Transforms/Scalar/LoopFlatten.cpp| 2 +- llvm/lib/Transforms/Utils/SimplifyCFG.cpp | 8 11 files changed, 40 insertions(+), 28 deletions(-) diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 65d9862621061..8dc828abf8aec 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -3218,7 +3218,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, Value *AlignmentValue = EmitScalarExpr(E->getArg(1)); ConstantInt *AlignmentCI = cast(AlignmentValue); if (AlignmentCI->getValue().ugt(llvm::Value::MaximumAlignment)) - AlignmentCI = ConstantInt::get(AlignmentCI->getType(), + AlignmentCI = ConstantInt::get(AlignmentCI->getIntegerType(), llvm::Value::MaximumAlignment); emitAlignmentAssumption(PtrValue, Ptr, @@ -17010,7 +17010,7 @@ Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned BuiltinID, Value *Op1 = EmitScalarExpr(E->getArg(1)); ConstantInt *AlignmentCI = cast(Op0); if (AlignmentCI->getValue().ugt(llvm::Value::MaximumAlignment)) - AlignmentCI = ConstantInt::get(AlignmentCI->getType(), + AlignmentCI = ConstantInt::get(AlignmentCI->getIntegerType(), llvm::Value::MaximumAlignment); emitAlignmentAssumption(Op1, E->getArg(1), @@ -17248,7 +17248,8 @@ Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned BuiltinID, Op0, llvm::FixedVectorType::get(ConvertType(E->getType()), 2)); if (getTarget().isLittleEndian()) - Index = ConstantInt::get(Index->getType(), 1 - Index->getZExtValue()); + Index = + ConstantInt::get(Index->getIntegerType(), 1 - Index->getZExtValue()); return Builder.CreateExtractElement(Unpacked, Index); } diff --git a/llvm/include/llvm/IR/Constants.h b/llvm/include/llvm/IR/Constants.h index 2f7fc5652c2cd..7bd8bfc477d78 100644 --- a/llvm/include/llvm/IR/Constants.h +++ b/llvm/include/llvm/IR/Constants.h @@ -136,7 +136,11 @@ class ConstantInt final : public ConstantData { inline const APInt () const { return Val; } /// getBitWidth - Return the bitwidth of this constant. - unsigned getBitWidth() const { return