[llvm] de8867a - [AMDGPUEmitPrintf] Don't require specific pointer element type
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 26 07:16:40 PST 2022
Author: Nikita Popov
Date: 2022-01-26T16:16:32+01:00
New Revision: de8867a0b6407c9b6d95a2ecb830256f0e224b52
URL: https://github.com/llvm/llvm-project/commit/de8867a0b6407c9b6d95a2ecb830256f0e224b52
DIFF: https://github.com/llvm/llvm-project/commit/de8867a0b6407c9b6d95a2ecb830256f0e224b52.diff
LOG: [AMDGPUEmitPrintf] Don't require specific pointer element type
Rather than checking for i8*, simply add a bitcast to i8*, so the
appendString() code sees the expected type.
Added:
Modified:
llvm/lib/Transforms/Utils/AMDGPUEmitPrintf.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Utils/AMDGPUEmitPrintf.cpp b/llvm/lib/Transforms/Utils/AMDGPUEmitPrintf.cpp
index b8b0bbbc7a4e..c734611836eb 100644
--- a/llvm/lib/Transforms/Utils/AMDGPUEmitPrintf.cpp
+++ b/llvm/lib/Transforms/Utils/AMDGPUEmitPrintf.cpp
@@ -22,19 +22,6 @@ using namespace llvm;
#define DEBUG_TYPE "amdgpu-emit-printf"
-static bool isCString(const Value *Arg) {
- auto Ty = Arg->getType();
- auto PtrTy = dyn_cast<PointerType>(Ty);
- if (!PtrTy)
- return false;
-
- auto IntTy = dyn_cast<IntegerType>(PtrTy->getPointerElementType());
- if (!IntTy)
- return false;
-
- return IntTy->getBitWidth() == 8;
-}
-
static Value *fitArgInto64Bits(IRBuilder<> &Builder, Value *Arg) {
auto Int64Ty = Builder.getInt64Ty();
auto Ty = Arg->getType();
@@ -176,13 +163,15 @@ static Value *callAppendStringN(IRBuilder<> &Builder, Value *Desc, Value *Str,
static Value *appendString(IRBuilder<> &Builder, Value *Desc, Value *Arg,
bool IsLast) {
+ Arg = Builder.CreateBitCast(
+ Arg, Builder.getInt8PtrTy(Arg->getType()->getPointerAddressSpace()));
auto Length = getStrlenWithNull(Builder, Arg);
return callAppendStringN(Builder, Desc, Arg, Length, IsLast);
}
static Value *processArg(IRBuilder<> &Builder, Value *Desc, Value *Arg,
bool SpecIsCString, bool IsLast) {
- if (SpecIsCString && isCString(Arg)) {
+ if (SpecIsCString && isa<PointerType>(Arg->getType())) {
return appendString(Builder, Desc, Arg, IsLast);
}
// If the format specifies a string but the argument is not, the frontend will
More information about the llvm-commits
mailing list