On Mon, Apr 23, 2012 at 2:27 PM, Richard Guenther <richard.guent...@gmail.com> wrote: > int foo (_Bool b) > { > if (b) > return 1; > else > return 0; > }
Indeed PHI-OPT performs the transformation on this code, too. But the resulting code on powerpc64 is fine: [stevenb@gcc1-power7 gcc]$ cat t.c.149t.optimized ;; Function foo (foo, funcdef_no=0, decl_uid=1996, cgraph_uid=0) foo (_Bool b) { int D.2006; <bb 2>: D.2006_4 = (int) b_2(D); return D.2006_4; } [stevenb@gcc1-power7 gcc]$ cat t.s .file "t.c" .section ".toc","aw" .section ".text" .align 2 .p2align 4,,15 .globl foo .section ".opd","aw" .align 3 foo: .quad .L.foo,.TOC.@tocbase,0 .previous .type foo, @function .L.foo: blr .long 0 .byte 0,0,0,0,0,0,0,0 .size foo,.-.L.foo .ident "GCC: (GNU) 4.8.0 20120418 (experimental) [trunk revision 186580]" [stevenb@gcc1-power7 gcc]$ However, this C test case shows the problem: [stevenb@gcc1-power7 gcc]$ head -n 24 t.c #define ONEUL (1UL) int foo (long unsigned int a) { _Bool b; long unsigned int cst, csui; if (a > 27) goto return_zero; /*cst = 217579583UL;*/ cst = (ONEUL << 0) | (ONEUL << 1) | (ONEUL << 2) | (ONEUL << 3) | (ONEUL << 4) | (ONEUL << 5) | (ONEUL << 19) | (ONEUL << 20) | (ONEUL << 21) | (ONEUL << 22) | (ONEUL << 23) | (ONEUL << 26) | (ONEUL << 27); csui = (ONEUL << a); b = ((csui & cst) != 0); if (b) return 1; else return 0; return_zero: return 0; } [stevenb@gcc1-power7 gcc]$ ./cc1 -quiet -O2 -fdump-tree-all t.c [stevenb@gcc1-power7 gcc]$ cat t.s .file "t.c" .section ".toc","aw" .section ".text" .align 2 .p2align 4,,15 .globl foo .section ".opd","aw" .align 3 foo: .quad .L.foo,.TOC.@tocbase,0 .previous .type foo, @function .L.foo: cmpldi 7,3,27 bgt 7,.L3 li 10,1 lis 9,0xcf8 sld 3,10,3 ori 9,9,63 and. 10,3,9 mfcr 9 rlwinm 9,9,3,1 xori 3,9,1 blr .p2align 4,,15 .L3: .L2: li 3,0 blr .long 0 .byte 0,0,0,0,0,0,0,0 .size foo,.-.L.foo .ident "GCC: (GNU) 4.8.0 20120418 (experimental) [trunk revision 186580]" I will file a PR for this later today, maybe after trying on a few other targets to see if this is a middle-end problem or a target issue. Ciao! Steven