Hello, Say the original type is Integer i16*, I want to create a v16i16* type to replace it. static Type *getVectorPtr(Type *Ty) { PointerType *PointerTy = dyn_cast<PointerType>(Ty); assert(PointerTy && "PointerType expected"); unsigned addSpace = PointerTy->getAddressSpace(); Type *ScalarType = PointerTy->getElementType(); VectorType *VectorType = VectorType::get(ScalarType, 16); return PointerType::get(VectorType, addSpace); } There's no isVectorPtr() check, so I add static bool isVectorPtr(Type *Ty) { bool a = false; if(Ty->isPointerTy() ){ PointerType *PointerTy = dyn_cast<PointerType>(Ty); Type *vt = PointerTy->getElementType(); a = vt->isVectorTy(); } return a; } Then meet the following error: Assertion failed: ResultElementType == cast<PointerType>(getType()->getScalarType())->getElementType(), file D:\cygwin64\home\celine\clang-102\llvm\include\llvm/IR/Instructions.h, line 958 I wonder how to create vector pointer type correctly? -- Best Regards, Celine -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20191021/23fa9134/attachment.html>
Tim Northover via llvm-dev
2019-Oct-21 16:17 UTC
[llvm-dev] How to create vector pointer type?
Hi Celine, On Mon, 21 Oct 2019 at 05:24, Celine via llvm-dev <llvm-dev at lists.llvm.org> wrote:> Then meet the following error: > Assertion failed: ResultElementType == cast<PointerType>(getType()->getScalarType())->getElementType(), file D:\cygwin64\home\celine\clang-102\llvm\include\llvm/IR/Instructions.h, line 958Both of your functions look sensible to me, but this assertion is from within GetElementPtrInst, so it's happening after you've done something with these types. You probably replaced a Value with a different one with this new type (or mutated it in place). That leaves the IR in an inconsistent state E.g. one operand of an add could be i16 and the other i32, or in this case a GEP thinks it's operating on an i16* to produce another i16*, but it's actually operating on a <16 x i16>*, which would produce another <16 x i16>*. If you're trying to change the type of a Value you generally have to recreate its whole chain of users until you can reunify the types. If this is vectorizing a loop, for example, the whole loop data-path would probably need to be recreated with the new vector type, and surrounded by pointer bitcasts ot <16 x i16>* at the beginning (and back to i16* at the end if anyone cares about the final pointer). Cheers. Tim.
Celine via llvm-dev
2019-Oct-22 12:47 UTC
[llvm-dev] 回复: How to create vector pointer type?
Thank you very much for this detail information~ ------------------ 原始邮件 ------------------ 发件人: "Tim Northover"<t.p.northover at gmail.com>; 发送时间: 2019年10月22日(星期二) 凌晨0:17 收件人: "Celine"<595602881 at qq.com>; 抄送: "llvm-dev"<llvm-dev at lists.llvm.org>; 主题: Re: [llvm-dev] How to create vector pointer type? Hi Celine, On Mon, 21 Oct 2019 at 05:24, Celine via llvm-dev <llvm-dev at lists.llvm.org> wrote: > Then meet the following error: > Assertion failed: ResultElementType == cast<PointerType>(getType()->getScalarType())->getElementType(), file D:\cygwin64\home\celine\clang-102\llvm\include\llvm/IR/Instructions.h, line 958 Both of your functions look sensible to me, but this assertion is from within GetElementPtrInst, so it's happening after you've done something with these types. You probably replaced a Value with a different one with this new type (or mutated it in place). That leaves the IR in an inconsistent state E.g. one operand of an add could be i16 and the other i32, or in this case a GEP thinks it's operating on an i16* to produce another i16*, but it's actually operating on a <16 x i16>*, which would produce another <16 x i16>*. If you're trying to change the type of a Value you generally have to recreate its whole chain of users until you can reunify the types. If this is vectorizing a loop, for example, the whole loop data-path would probably need to be recreated with the new vector type, and surrounded by pointer bitcasts ot <16 x i16>* at the beginning (and back to i16* at the end if anyone cares about the final pointer). Cheers. Tim. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20191022/5f6dc5ff/attachment.html>
Maybe Matching Threads
- [LLVMdev] DebugInfo/PDB/pdbdump-symbol-format.test fails with VS 2015
- [LLVMdev] DebugInfo/PDB/pdbdump-symbol-format.test fails with VS 2015
- [LLVMdev] DebugInfo/PDB/pdbdump-symbol-format.test fails with VS 2015
- problem with compiling on Cygwin64
- [LLVMdev] New strict-aliasing warning?