Hi Akira,> This is the definition of BITCAST in include/llvm/CodeGen/ISDOpcodes.h: > > // BITCAST - This operator converts between integer, vector and FP > // values, as if the value was stored to memory with one type and loaded > // from the same address with the other type (or equivalently for vector > // format conversions, etc). The source and result are required to have > // the same bit size (e.g. f32 <-> i32). This can also be used for > // int-to-int or fp-to-fp conversions, but that is a noop, deleted by > // getNode(). > > If I can assume the bitcast instruction in LLVM IR has the same definition, does > this mean that the following instruction > > %dst = bitcast i32 %src to v2i16 > > is equivalent to the following sequence of instructions (which I think is lossless)? > > store i32 %src, i32* %ptr > %ptr2 = bitcast i32* %ptr to v2i16* > %dst = load v2i16* %ptr2while there has been some discussion about changing the definition of bitcast, yes, this is currently the definition. That canLoslesslyBitCastTo returns false for bitcast of i32 to <2 x i16> is probably just an oversight. Please feel free to send in a patch fixing it. Ciao, Duncan.> > > I am trying to change all vector types (v2i16 and v4i8) in > include/llvm/IntrinsicsMips.td to i32, but I can't do that because the code in > CodeGenFunction::EmitBuiltinExpr (in clang/CGBuiltin.cpp) raises an assertion > when it calls Type::canLoslesslyBitCastTo to check whether conversion between > v2i16 (or v4i8) and i32 is legal. > > To work around this problem, I can put back CodeGenFunction::EmitMipsBuiltinExpr > which was removed in r159368 and add code to do type conversions, but I prefer > not to do this. > > > On Mon, Jul 2, 2012 at 5:40 PM, Akira Hatanaka <ahatanak at gmail.com > <mailto:ahatanak at gmail.com>> wrote: > > Type::canLoslesslyBitCastTo(Type *Ty) in lib/VMCore/Type.cpp always returns > false when it checks whether an integer can be bitcast to a vector or vice > versa. > > For example, (i32 => v2i16) or (v2i16 => i32) is false. > > But it seems that it returns true if it is checking conversion between two > vector types which have the same size. > > For example, (v4i8 => v2i16) would return true. > > What is the rationale behind this? > > > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >
Hi Duncan and llvm developers, The attached patch makes the function return true if the conversion is between a vector and an integer of the same size. Please review when you have time. On Tue, Jul 10, 2012 at 12:21 AM, Duncan Sands <baldrick at free.fr> wrote:> Hi Akira, > > > This is the definition of BITCAST in include/llvm/CodeGen/ISDOpcodes.h: > > > > // BITCAST - This operator converts between integer, vector and FP > > // values, as if the value was stored to memory with one type and loaded > > // from the same address with the other type (or equivalently for vector > > // format conversions, etc). The source and result are required to have > > // the same bit size (e.g. f32 <-> i32). This can also be used for > > // int-to-int or fp-to-fp conversions, but that is a noop, deleted by > > // getNode(). > > > > If I can assume the bitcast instruction in LLVM IR has the same > definition, does > > this mean that the following instruction > > > > %dst = bitcast i32 %src to v2i16 > > > > is equivalent to the following sequence of instructions (which I think > is lossless)? > > > > store i32 %src, i32* %ptr > > %ptr2 = bitcast i32* %ptr to v2i16* > > %dst = load v2i16* %ptr2 > > while there has been some discussion about changing the definition of > bitcast, > yes, this is currently the definition. That canLoslesslyBitCastTo returns > false for bitcast of i32 to <2 x i16> is probably just an oversight. > Please > feel free to send in a patch fixing it. > > Ciao, Duncan. > > > > > > > I am trying to change all vector types (v2i16 and v4i8) in > > include/llvm/IntrinsicsMips.td to i32, but I can't do that because the > code in > > CodeGenFunction::EmitBuiltinExpr (in clang/CGBuiltin.cpp) raises an > assertion > > when it calls Type::canLoslesslyBitCastTo to check whether conversion > between > > v2i16 (or v4i8) and i32 is legal. > > > > To work around this problem, I can put back > CodeGenFunction::EmitMipsBuiltinExpr > > which was removed in r159368 and add code to do type conversions, but I > prefer > > not to do this. > > > > > > On Mon, Jul 2, 2012 at 5:40 PM, Akira Hatanaka <ahatanak at gmail.com > > <mailto:ahatanak at gmail.com>> wrote: > > > > Type::canLoslesslyBitCastTo(Type *Ty) in lib/VMCore/Type.cpp always > returns > > false when it checks whether an integer can be bitcast to a vector > or vice > > versa. > > > > For example, (i32 => v2i16) or (v2i16 => i32) is false. > > > > But it seems that it returns true if it is checking conversion > between two > > vector types which have the same size. > > > > For example, (v4i8 => v2i16) would return true. > > > > What is the rationale behind this? > > > > > > > > > > _______________________________________________ > > LLVM Developers mailing list > > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > > > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120716/0ada8833/attachment.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: losslessbitcast.patch Type: text/x-patch Size: 1827 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120716/0ada8833/attachment.bin>
Ping? Any comments or suggestions? On Mon, Jul 16, 2012 at 4:52 PM, Akira Hatanaka <ahatanak at gmail.com> wrote:> Hi Duncan and llvm developers, > > The attached patch makes the function return true if the conversion is > between a vector and an integer of the same size. > > Please review when you have time. > > > On Tue, Jul 10, 2012 at 12:21 AM, Duncan Sands <baldrick at free.fr> wrote: > >> Hi Akira, >> >> > This is the definition of BITCAST in include/llvm/CodeGen/ISDOpcodes.h: >> > >> > // BITCAST - This operator converts between integer, vector and FP >> > // values, as if the value was stored to memory with one type and loaded >> > // from the same address with the other type (or equivalently for vector >> > // format conversions, etc). The source and result are required to have >> > // the same bit size (e.g. f32 <-> i32). This can also be used for >> > // int-to-int or fp-to-fp conversions, but that is a noop, deleted by >> > // getNode(). >> > >> > If I can assume the bitcast instruction in LLVM IR has the same >> definition, does >> > this mean that the following instruction >> > >> > %dst = bitcast i32 %src to v2i16 >> > >> > is equivalent to the following sequence of instructions (which I think >> is lossless)? >> > >> > store i32 %src, i32* %ptr >> > %ptr2 = bitcast i32* %ptr to v2i16* >> > %dst = load v2i16* %ptr2 >> >> while there has been some discussion about changing the definition of >> bitcast, >> yes, this is currently the definition. That canLoslesslyBitCastTo returns >> false for bitcast of i32 to <2 x i16> is probably just an oversight. >> Please >> feel free to send in a patch fixing it. >> >> Ciao, Duncan. >> >> > >> > >> > I am trying to change all vector types (v2i16 and v4i8) in >> > include/llvm/IntrinsicsMips.td to i32, but I can't do that because the >> code in >> > CodeGenFunction::EmitBuiltinExpr (in clang/CGBuiltin.cpp) raises an >> assertion >> > when it calls Type::canLoslesslyBitCastTo to check whether conversion >> between >> > v2i16 (or v4i8) and i32 is legal. >> > >> > To work around this problem, I can put back >> CodeGenFunction::EmitMipsBuiltinExpr >> > which was removed in r159368 and add code to do type conversions, but I >> prefer >> > not to do this. >> > >> > >> > On Mon, Jul 2, 2012 at 5:40 PM, Akira Hatanaka <ahatanak at gmail.com >> > <mailto:ahatanak at gmail.com>> wrote: >> > >> > Type::canLoslesslyBitCastTo(Type *Ty) in lib/VMCore/Type.cpp always >> returns >> > false when it checks whether an integer can be bitcast to a vector >> or vice >> > versa. >> > >> > For example, (i32 => v2i16) or (v2i16 => i32) is false. >> > >> > But it seems that it returns true if it is checking conversion >> between two >> > vector types which have the same size. >> > >> > For example, (v4i8 => v2i16) would return true. >> > >> > What is the rationale behind this? >> > >> > >> > >> > >> > _______________________________________________ >> > LLVM Developers mailing list >> > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >> > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >> > >> >> >> _______________________________________________ >> LLVM Developers mailing list >> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >> > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120725/8b169c36/attachment.html>
Reasonably Related Threads
- [LLVMdev] question about Type::canLoslesslyBitCastTo
- [LLVMdev] question about Type::canLoslesslyBitCastTo
- [LLVMdev] question about Type::canLoslesslyBitCastTo
- [LLVMdev] How to define macros in a tablegen file?
- [LLVMdev] How to define macros in a tablegen file?