Hi Andrew, On 11 July 2018 at 15:43, Andrew Pinski <pins...@gmail.com> wrote: > On Tue, Jul 10, 2018 at 6:35 PM Kugan Vivekanandarajah > <kugan.vivekanandara...@linaro.org> wrote: >> >> Hi Andrew, >> >> On 11 July 2018 at 11:19, Andrew Pinski <pins...@gmail.com> wrote: >> > On Tue, Jul 10, 2018 at 6:14 PM Kugan Vivekanandarajah >> > <kugan.vivekanandara...@linaro.org> wrote: >> >> >> >> On 10 July 2018 at 23:17, Richard Biener <richard.guent...@gmail.com> >> >> wrote: >> >> > On Tue, Jul 10, 2018 at 3:06 PM Kugan Vivekanandarajah >> >> > <kugan.vivekanandara...@linaro.org> wrote: >> >> >> >> >> >> Hi, >> >> >> >> >> >> Jeff told me that the recent popcount built-in detection is causing >> >> >> kernel build issues as >> >> >> ERROR: "__popcountsi2" >> >> >> [drivers/net/wireless/broadcom/brcm80211/brcmfmac/brcmfmac.ko] >> >> >> undefined! >> >> >> >> >> >> I could also reproduce this. AFIK, we should check if the libfunc is >> >> >> defined while checking popcount? >> >> >> >> >> >> I am testing the attached RFC patch. Is this reasonable? >> >> > >> >> > It doesn't work that way, all targets have this libfunc in libgcc. >> >> > This means >> >> > the kernel has to provide it. The only thing you could do is restrict >> >> > replacement of CALL_EXPRs (in SCEV cprop) to those the target >> >> > natively supports. >> >> >> >> How about restricting it in expression_expensive_p ? Is that what you >> >> wanted. Attached patch does this. >> >> Bootstrap and regression testing progressing. >> > >> > Seems like that should go into is_inexpensive_builtin instead which >> > is just tested right below. >> >> I hought about that. is_inexpensive_builtin is used in various other >> places including some inlining decision so wasn't sure if it is the >> right thing. Happy to change it if that is the right thing to do. > > I audited all of the users (and their users if it is used in a > wrapper) and found that is_inexpensive_builtin should return false for > this builtin if it is a function call in the end; there are other > builtins which should be checked the similar way but I think we should > not going to force you to do the similar thing for those builtins.
Attached patch does this. Testing is progressing. Is This OK if no regression. Thanks, Kugan > > Thanks, > Andrew > >> >> Thanks, >> Kugan >> > >> > Thanks, >> > Andrew >> > >> >> >> >> Thanks, >> >> Kugan >> >> >> >> > >> >> > Richard. >> >> > >> >> >> Thanks, >> >> >> Kugan >> >> >> >> >> >> gcc/ChangeLog: >> >> >> >> >> >> 2018-07-10 Kugan Vivekanandarajah <kug...@linaro.org> >> >> >> >> >> >> * tree-ssa-loop-niter.c (number_of_iterations_popcount): Check >> >> >> if libfunc for popcount is available.
diff --git a/gcc/builtins.c b/gcc/builtins.c index 820d6c2..59cf567 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -10619,6 +10619,18 @@ is_inexpensive_builtin (tree decl) else if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL) switch (DECL_FUNCTION_CODE (decl)) { + case BUILT_IN_POPCOUNT: + case BUILT_IN_POPCOUNTL: + case BUILT_IN_POPCOUNTLL: + { + tree arg = TYPE_ARG_TYPES (TREE_TYPE (decl)); + /* Check if opcode for popcount is available. */ + if (optab_handler (popcount_optab, + TYPE_MODE (TREE_VALUE (arg))) + == CODE_FOR_nothing) + return false; + } + return true; case BUILT_IN_ABS: CASE_BUILT_IN_ALLOCA: case BUILT_IN_BSWAP16: @@ -10670,10 +10682,7 @@ is_inexpensive_builtin (tree decl) case BUILT_IN_VA_COPY: case BUILT_IN_TRAP: case BUILT_IN_SAVEREGS: - case BUILT_IN_POPCOUNTL: - case BUILT_IN_POPCOUNTLL: case BUILT_IN_POPCOUNTIMAX: - case BUILT_IN_POPCOUNT: case BUILT_IN_PARITYL: case BUILT_IN_PARITYLL: case BUILT_IN_PARITYIMAX: diff --git a/gcc/testsuite/gcc.target/aarch64/popcount4.c b/gcc/testsuite/gcc.target/aarch64/popcount4.c index e69de29..ee55b2e 100644 --- a/gcc/testsuite/gcc.target/aarch64/popcount4.c +++ b/gcc/testsuite/gcc.target/aarch64/popcount4.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized -mgeneral-regs-only" } */ + +int PopCount (long b) { + int c = 0; + + while (b) { + b &= b - 1; + c++; + } + return c; +} + +/* { dg-final { scan-tree-dump-times "__builtin_popcount" 0 "optimized" } } */