Index: include/llvm/Analysis/TargetLibraryInfo.h =================================================================== --- include/llvm/Analysis/TargetLibraryInfo.h +++ include/llvm/Analysis/TargetLibraryInfo.h @@ -51,6 +51,7 @@ unsigned char AvailableArray[(LibFunc::NumLibFuncs+3)/4]; llvm::DenseMap CustomNames; static const char *const StandardNames[LibFunc::NumLibFuncs]; + bool ShouldExtI32Param, ShouldExtI32Return; enum AvailabilityState { StandardName = 3, // (memset to all ones) @@ -171,6 +172,18 @@ /// /// Set VF to the vectorization factor. StringRef getScalarizedFunction(StringRef F, unsigned &VF) const; + + /// Set whether int and unsigned int parameters should have + /// signext or zeroext attributes, respectively. + void setShouldExtI32Param(bool Param) { + ShouldExtI32Param = Param; + } + + /// Set whether int and unsigned int returns should have + /// signext or zeroext attributes, respectively. + void setShouldExtI32Return(bool Return) { + ShouldExtI32Return = Return; + } }; /// Provides information about what library functions are available for @@ -267,6 +280,20 @@ return Impl->CustomNames.find(F)->second; } + /// Returns true iff i32 parameters to library functions should have + /// signext or zeroext attributes if they correspond to C-level int or + /// unsigned int, respectively. + bool shouldExtI32Param() const { + return Impl->ShouldExtI32Param; + } + + /// Returns true iff i32 returns from library functions should have + /// signext or zeroext attributes if they correspond to C-level int or + /// unsigned int, respectively. + bool shouldExtI32Return() const { + return Impl->ShouldExtI32Return; + } + /// Handle invalidation from the pass manager. /// /// If we try to invalidate this info, just return false. It cannot become Index: lib/Analysis/TargetLibraryInfo.cpp =================================================================== --- lib/Analysis/TargetLibraryInfo.cpp +++ lib/Analysis/TargetLibraryInfo.cpp @@ -412,6 +412,20 @@ } TLI.addVectorizableFunctionsFromVecLib(ClVectorLibrary); + + // PowerPC64, Sparc64, SystemZ need signext/zeroext on i32 parameters and + // returns corresponding to C-level ints. Mips64 needs it for parameters + // only. + bool ShouldExtI32Param = false, ShouldExtI32Return = false; + if (T.getArch() == Triple::ppc64 || T.getArch() == Triple::ppc64le || + T.getArch() == Triple::sparcv9 || T.getArch() == Triple::systemz) { + ShouldExtI32Param = true; + ShouldExtI32Return = true; + } + if (T.getArch() == Triple::mips64 || T.getArch() == Triple::mips64el) + ShouldExtI32Param = true; + TLI.setShouldExtI32Param(ShouldExtI32Param); + TLI.setShouldExtI32Return(ShouldExtI32Return); } TargetLibraryInfoImpl::TargetLibraryInfoImpl() { @@ -429,14 +443,17 @@ } TargetLibraryInfoImpl::TargetLibraryInfoImpl(const TargetLibraryInfoImpl &TLI) - : CustomNames(TLI.CustomNames) { + : CustomNames(TLI.CustomNames), ShouldExtI32Param(TLI.ShouldExtI32Param), + ShouldExtI32Return(TLI.ShouldExtI32Return) { memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray)); VectorDescs = TLI.VectorDescs; ScalarDescs = TLI.ScalarDescs; } TargetLibraryInfoImpl::TargetLibraryInfoImpl(TargetLibraryInfoImpl &&TLI) - : CustomNames(std::move(TLI.CustomNames)) { + : CustomNames(std::move(TLI.CustomNames)), + ShouldExtI32Param(TLI.ShouldExtI32Param), + ShouldExtI32Return(TLI.ShouldExtI32Return) { std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray), AvailableArray); VectorDescs = TLI.VectorDescs; @@ -445,12 +462,16 @@ TargetLibraryInfoImpl &TargetLibraryInfoImpl::operator=(const TargetLibraryInfoImpl &TLI) { CustomNames = TLI.CustomNames; + ShouldExtI32Param = TLI.ShouldExtI32Param; + ShouldExtI32Return = TLI.ShouldExtI32Return; memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray)); return *this; } TargetLibraryInfoImpl &TargetLibraryInfoImpl::operator=(TargetLibraryInfoImpl &&TLI) { CustomNames = std::move(TLI.CustomNames); + ShouldExtI32Param = TLI.ShouldExtI32Param; + ShouldExtI32Return = TLI.ShouldExtI32Return; std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray), AvailableArray); return *this;