Hello, i need to fold constants, i found that a function ConstantFoldConstantExpression could be used, however I am not able to make it fold anything. Could you please give me some advice, what I am doing wrong? My code looks something like this: //data layout is obtained from clang-generated code for triple arm-none-linux-gnueabi with added v32:32:32 const char* const TARGET_DATA_LAYOUT "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v32:32:32-v64:64:64-v128:128:128-a0:0:64-n32"; TargetData TD(TARGET_DATA_LAYOUT); void transformConstantExpr(ConstantExpr* cop) { Constant* val = ConstantFoldConstantExpression(cop, &TD); if (val != NULL) { errs() << "**" << *cop << " to \n--" << *val << "\n"; } } And this is the output i get, all constants should result in "i32 0" (at least this is what I need): **i32 bitcast (<4 x i8> zeroinitializer to i32) to --i32 bitcast (<4 x i8> zeroinitializer to i32) **i32 sext (i8 trunc (i32 bitcast (<4 x i8> zeroinitializer to i32) to i8) to i32) to --i32 sext (i8 trunc (i32 bitcast (<4 x i8> zeroinitializer to i32) to i8) to i32) **i32 bitcast (<4 x i8> <i8 trunc (i32 shl (i32 sext (i8 trunc (i32 bitcast (<4 x i8> zeroinitializer to i32) to i8) to i32), i32 0) to i8), i8 0, i8 0, i8 0> to i32) to --i32 bitcast (<4 x i8> <i8 trunc (i32 shl (i32 sext (i8 trunc (i32 bitcast (<4 x i8> zeroinitializer to i32) to i8) to i32), i32 0) to i8), i8 0, i8 0, i8 0> to i32) **i32 and (i32 bitcast (<4 x i8> zeroinitializer to i32), i32 255) to --i32 and (i32 bitcast (<4 x i8> zeroinitializer to i32), i32 255) **i32 bitcast (<4 x i8> <i8 trunc (i32 lshr (i32 and (i32 bitcast (<4 x i8> zeroinitializer to i32), i32 255), i32 0) to i8), i8 0, i8 0, i8 0> to i32) to --i32 bitcast (<4 x i8> <i8 trunc (i32 lshr (i32 and (i32 bitcast (<4 x i8> zeroinitializer to i32), i32 255), i32 0) to i8), i8 0, i8 0, i8 0> to i32) **i32 bitcast (<4 x i8> <i8 trunc (i32 bitcast (<4 x i8> zeroinitializer to i32) to i8), i8 0, i8 0, i8 0> to i32) to --i32 bitcast (<4 x i8> <i8 trunc (i32 bitcast (<4 x i8> zeroinitializer to i32) to i8), i8 0, i8 0, i8 0> to i32) **i32 bitcast (<2 x i16> zeroinitializer to i32) to --i32 bitcast (<2 x i16> zeroinitializer to i32) **i32 bitcast (<4 x i8> bitcast (i32 bitcast (<2 x i16> <i16 zext (i8 extractelement (<4 x i8> bitcast (i32 bitcast (<4 x i8> zeroinitializer to i32) to <4 x i8>), i32 2) to i16), i16 zext (i8 extractelement (<4 x i8> bitcast (i32 bitcast (<4 x i8> zeroinitializer to i32) to <4 x i8>), i32 3) to i16)> to i32) to <4 x i8>) to i32) to --i32 bitcast (<4 x i8> bitcast (i32 bitcast (<2 x i16> <i16 zext (i8 extractelement (<4 x i8> bitcast (i32 bitcast (<4 x i8> zeroinitializer to i32) to <4 x i8>), i32 2) to i16), i16 zext (i8 extractelement (<4 x i8> bitcast (i32 bitcast (<4 x i8> zeroinitializer to i32) to <4 x i8>), i32 3) to i16)> to i32) to <4 x i8>) to i32) Have I something wrong in the TargetData or do I miss something else? I tried also big endian, but it did not help. Thank you Adam Husar
I forgot to mention, that I use LLVM release 2.8, I did not try it with the latest revision, but I expect that I am rather doing something wrong than using non-implemented functions. On Tue, 15 Feb 2011 14:09:57 +0100, ihusar <ihusar at fit.vutbr.cz> wrote:> Hello, > > i need to fold constants, i found that a function ConstantFoldConstantExpression could be used, > however I am not able to make it fold anything. Could you please give me some advice, what I am doing wrong? > > > My code looks something like this: > > //data layout is obtained from clang-generated code for triple arm-none-linux-gnueabi with added v32:32:32 > const char* const TARGET_DATA_LAYOUT > "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v32:32:32-v64:64:64-v128:128:128-a0:0:64-n32"; > > TargetData TD(TARGET_DATA_LAYOUT); > > void transformConstantExpr(ConstantExpr* cop) > { > Constant* val = ConstantFoldConstantExpression(cop, &TD); > if (val != NULL) > { > errs() << "**" << *cop << " to \n--" << *val << "\n"; > } > } > > And this is the output i get, all constants should result in "i32 0" (at least this is what I need): > > **i32 bitcast (<4 x i8> zeroinitializer to i32) to > --i32 bitcast (<4 x i8> zeroinitializer to i32) > > **i32 sext (i8 trunc (i32 bitcast (<4 x i8> zeroinitializer to i32) to i8) to i32) to > --i32 sext (i8 trunc (i32 bitcast (<4 x i8> zeroinitializer to i32) to i8) to i32) > > **i32 bitcast (<4 x i8> <i8 trunc (i32 shl (i32 sext (i8 trunc (i32 bitcast (<4 x i8> zeroinitializer to i32) to i8) to i32), i32 0) to i8), i8 0, i8 0, i8 0> to i32) to > --i32 bitcast (<4 x i8> <i8 trunc (i32 shl (i32 sext (i8 trunc (i32 bitcast (<4 x i8> zeroinitializer to i32) to i8) to i32), i32 0) to i8), i8 0, i8 0, i8 0> to i32) > > **i32 and (i32 bitcast (<4 x i8> zeroinitializer to i32), i32 255) to > --i32 and (i32 bitcast (<4 x i8> zeroinitializer to i32), i32 255) > > **i32 bitcast (<4 x i8> <i8 trunc (i32 lshr (i32 and (i32 bitcast (<4 x i8> zeroinitializer to i32), i32 255), i32 0) to i8), i8 0, i8 0, i8 0> to i32) to > --i32 bitcast (<4 x i8> <i8 trunc (i32 lshr (i32 and (i32 bitcast (<4 x i8> zeroinitializer to i32), i32 255), i32 0) to i8), i8 0, i8 0, i8 0> to i32) > > **i32 bitcast (<4 x i8> <i8 trunc (i32 bitcast (<4 x i8> zeroinitializer to i32) to i8), i8 0, i8 0, i8 0> to i32) to > --i32 bitcast (<4 x i8> <i8 trunc (i32 bitcast (<4 x i8> zeroinitializer to i32) to i8), i8 0, i8 0, i8 0> to i32) > > **i32 bitcast (<2 x i16> zeroinitializer to i32) to > --i32 bitcast (<2 x i16> zeroinitializer to i32) > > **i32 bitcast (<4 x i8> bitcast (i32 bitcast (<2 x i16> <i16 zext (i8 extractelement (<4 x i8> bitcast (i32 bitcast (<4 x i8> zeroinitializer to i32) to <4 x i8>), i32 2) to i16), i16 zext (i8 extractelement (<4 x i8> bitcast (i32 bitcast (<4 x i8> zeroinitializer to i32) to <4 x i8>), i32 3) to i16)> to i32) to <4 x i8>) to i32) to > --i32 bitcast (<4 x i8> bitcast (i32 bitcast (<2 x i16> <i16 zext (i8 extractelement (<4 x i8> bitcast (i32 bitcast (<4 x i8> zeroinitializer to i32) to <4 x i8>), i32 2) to i16), i16 zext (i8 extractelement (<4 x i8> bitcast (i32 bitcast (<4 x i8> zeroinitializer to i32) to <4 x i8>), i32 3) to i16)> to i32) to <4 x i8>) to i32) > > > Have I something wrong in the TargetData or do I miss something else? > I tried also big endian, but it did not help. > > Thank you > Adam Husar > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Adam, I just fixed this issue a few days ago. A version from the trunk should work for you. Cheers, Nadav -----Original Message----- From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] On Behalf Of ihusar Sent: Tuesday, February 15, 2011 15:52 To: llvmdev at cs.uiuc.edu Subject: Re: [LLVMdev] How to use ConstantFoldConstantExpression? I forgot to mention, that I use LLVM release 2.8, I did not try it with the latest revision, but I expect that I am rather doing something wrong than using non-implemented functions. On Tue, 15 Feb 2011 14:09:57 +0100, ihusar <ihusar at fit.vutbr.cz> wrote:> Hello, > > i need to fold constants, i found that a function ConstantFoldConstantExpression could be used, > however I am not able to make it fold anything. Could you please give me some advice, what I am doing wrong? > > > My code looks something like this: > > //data layout is obtained from clang-generated code for triple arm-none-linux-gnueabi with added v32:32:32 > const char* const TARGET_DATA_LAYOUT > "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v32:32:32-v64:64:64-v128:128:128-a0:0:64-n32"; > > TargetData TD(TARGET_DATA_LAYOUT); > > void transformConstantExpr(ConstantExpr* cop) > { > Constant* val = ConstantFoldConstantExpression(cop, &TD); > if (val != NULL) > { > errs() << "**" << *cop << " to \n--" << *val << "\n"; > } > } > > And this is the output i get, all constants should result in "i32 0" (at least this is what I need): > > **i32 bitcast (<4 x i8> zeroinitializer to i32) to > --i32 bitcast (<4 x i8> zeroinitializer to i32) > > **i32 sext (i8 trunc (i32 bitcast (<4 x i8> zeroinitializer to i32) to i8) to i32) to > --i32 sext (i8 trunc (i32 bitcast (<4 x i8> zeroinitializer to i32) to i8) to i32) > > **i32 bitcast (<4 x i8> <i8 trunc (i32 shl (i32 sext (i8 trunc (i32 bitcast (<4 x i8> zeroinitializer to i32) to i8) to i32), i32 0) to i8), i8 0, i8 0, i8 0> to i32) to > --i32 bitcast (<4 x i8> <i8 trunc (i32 shl (i32 sext (i8 trunc (i32 bitcast (<4 x i8> zeroinitializer to i32) to i8) to i32), i32 0) to i8), i8 0, i8 0, i8 0> to i32) > > **i32 and (i32 bitcast (<4 x i8> zeroinitializer to i32), i32 255) to > --i32 and (i32 bitcast (<4 x i8> zeroinitializer to i32), i32 255) > > **i32 bitcast (<4 x i8> <i8 trunc (i32 lshr (i32 and (i32 bitcast (<4 x i8> zeroinitializer to i32), i32 255), i32 0) to i8), i8 0, i8 0, i8 0> to i32) to > --i32 bitcast (<4 x i8> <i8 trunc (i32 lshr (i32 and (i32 bitcast (<4 x i8> zeroinitializer to i32), i32 255), i32 0) to i8), i8 0, i8 0, i8 0> to i32) > > **i32 bitcast (<4 x i8> <i8 trunc (i32 bitcast (<4 x i8> zeroinitializer to i32) to i8), i8 0, i8 0, i8 0> to i32) to > --i32 bitcast (<4 x i8> <i8 trunc (i32 bitcast (<4 x i8> zeroinitializer to i32) to i8), i8 0, i8 0, i8 0> to i32) > > **i32 bitcast (<2 x i16> zeroinitializer to i32) to > --i32 bitcast (<2 x i16> zeroinitializer to i32) > > **i32 bitcast (<4 x i8> bitcast (i32 bitcast (<2 x i16> <i16 zext (i8 extractelement (<4 x i8> bitcast (i32 bitcast (<4 x i8> zeroinitializer to i32) to <4 x i8>), i32 2) to i16), i16 zext (i8 extractelement (<4 x i8> bitcast (i32 bitcast (<4 x i8> zeroinitializer to i32) to <4 x i8>), i32 3) to i16)> to i32) to <4 x i8>) to i32) to > --i32 bitcast (<4 x i8> bitcast (i32 bitcast (<2 x i16> <i16 zext (i8 extractelement (<4 x i8> bitcast (i32 bitcast (<4 x i8> zeroinitializer to i32) to <4 x i8>), i32 2) to i16), i16 zext (i8 extractelement (<4 x i8> bitcast (i32 bitcast (<4 x i8> zeroinitializer to i32) to <4 x i8>), i32 3) to i16)> to i32) to <4 x i8>) to i32) > > > Have I something wrong in the TargetData or do I miss something else? > I tried also big endian, but it did not help. > > Thank you > Adam Husar > _______________________________________________ > 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 --------------------------------------------------------------------- Intel Israel (74) Limited This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.
Hi,> I forgot to mention, that I use LLVM release 2.8, I did not try it with the latest revision, but I expect that I > am rather doing something wrong than using non-implemented functions.the constant folder has historically done a poor job of folding vector expressions. Does it succeed in folding non-vector expressions? Ciao, Duncan.> > On Tue, 15 Feb 2011 14:09:57 +0100, ihusar<ihusar at fit.vutbr.cz> wrote: > >> Hello, >> >> i need to fold constants, i found that a function ConstantFoldConstantExpression could be used, >> however I am not able to make it fold anything. Could you please give me some advice, what I am doing wrong? >> >> >> My code looks something like this: >> >> //data layout is obtained from clang-generated code for triple arm-none-linux-gnueabi with added v32:32:32 >> const char* const TARGET_DATA_LAYOUT >> "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v32:32:32-v64:64:64-v128:128:128-a0:0:64-n32"; >> >> TargetData TD(TARGET_DATA_LAYOUT); >> >> void transformConstantExpr(ConstantExpr* cop) >> { >> Constant* val = ConstantFoldConstantExpression(cop,&TD); >> if (val != NULL) >> { >> errs()<< "**"<< *cop<< " to \n--"<< *val<< "\n"; >> } >> } >> >> And this is the output i get, all constants should result in "i32 0" (at least this is what I need): >> >> **i32 bitcast (<4 x i8> zeroinitializer to i32) to >> --i32 bitcast (<4 x i8> zeroinitializer to i32) >> >> **i32 sext (i8 trunc (i32 bitcast (<4 x i8> zeroinitializer to i32) to i8) to i32) to >> --i32 sext (i8 trunc (i32 bitcast (<4 x i8> zeroinitializer to i32) to i8) to i32) >> >> **i32 bitcast (<4 x i8> <i8 trunc (i32 shl (i32 sext (i8 trunc (i32 bitcast (<4 x i8> zeroinitializer to i32) to i8) to i32), i32 0) to i8), i8 0, i8 0, i8 0> to i32) to >> --i32 bitcast (<4 x i8> <i8 trunc (i32 shl (i32 sext (i8 trunc (i32 bitcast (<4 x i8> zeroinitializer to i32) to i8) to i32), i32 0) to i8), i8 0, i8 0, i8 0> to i32) >> >> **i32 and (i32 bitcast (<4 x i8> zeroinitializer to i32), i32 255) to >> --i32 and (i32 bitcast (<4 x i8> zeroinitializer to i32), i32 255) >> >> **i32 bitcast (<4 x i8> <i8 trunc (i32 lshr (i32 and (i32 bitcast (<4 x i8> zeroinitializer to i32), i32 255), i32 0) to i8), i8 0, i8 0, i8 0> to i32) to >> --i32 bitcast (<4 x i8> <i8 trunc (i32 lshr (i32 and (i32 bitcast (<4 x i8> zeroinitializer to i32), i32 255), i32 0) to i8), i8 0, i8 0, i8 0> to i32) >> >> **i32 bitcast (<4 x i8> <i8 trunc (i32 bitcast (<4 x i8> zeroinitializer to i32) to i8), i8 0, i8 0, i8 0> to i32) to >> --i32 bitcast (<4 x i8> <i8 trunc (i32 bitcast (<4 x i8> zeroinitializer to i32) to i8), i8 0, i8 0, i8 0> to i32) >> >> **i32 bitcast (<2 x i16> zeroinitializer to i32) to >> --i32 bitcast (<2 x i16> zeroinitializer to i32) >> >> **i32 bitcast (<4 x i8> bitcast (i32 bitcast (<2 x i16> <i16 zext (i8 extractelement (<4 x i8> bitcast (i32 bitcast (<4 x i8> zeroinitializer to i32) to<4 x i8>), i32 2) to i16), i16 zext (i8 extractelement (<4 x i8> bitcast (i32 bitcast (<4 x i8> zeroinitializer to i32) to<4 x i8>), i32 3) to i16)> to i32) to<4 x i8>) to i32) to >> --i32 bitcast (<4 x i8> bitcast (i32 bitcast (<2 x i16> <i16 zext (i8 extractelement (<4 x i8> bitcast (i32 bitcast (<4 x i8> zeroinitializer to i32) to<4 x i8>), i32 2) to i16), i16 zext (i8 extractelement (<4 x i8> bitcast (i32 bitcast (<4 x i8> zeroinitializer to i32) to<4 x i8>), i32 3) to i16)> to i32) to<4 x i8>) to i32) >> >> >> Have I something wrong in the TargetData or do I miss something else? >> I tried also big endian, but it did not help. >> >> Thank you >> Adam Husar >> _______________________________________________ >> 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
Possibly Parallel Threads
- [LLVMdev] How to use ConstantFoldConstantExpression?
- [LLVMdev] How to use ConstantFoldConstantExpression?
- [LLVMdev] loop vectorizer: Unexpected extract/insertelement
- [LLVMdev] loop vectorizer: Unexpected extract/insertelement
- [LLVMdev] loop vectorizer: Unexpected extract/insertelement