https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103784

            Bug ID: 103784
           Summary: suboptimal code for returning bool value on target ppc
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: guihaoc at gcc dot gnu.org
  Target Milestone: ---

//test.c

#include <stdbool.h>

bool foo (int a, int b)
{
  if (a > 2)
    return false;
  if (b < 10)
    return true;
  return true;
}

//assembly with trunk
        ld 9,0(3)
        cmpdi 0,9,0
        add 10,9,4
        beq 0,.L5
        ldarx 8,0,3
        cmpd 0,8,9
        bne 0,.L4
        stdcx. 10,0,3
        bne 0,.L4
        li 3,1
        rldicl 3,3,0,63
        blr
        .p2align 4,,15
.L5:
        li 3,0
        rldicl 3,3,0,63
        blr

//assembly with at13.0
        subfic 3,3,2
        srdi 3,3,63
        xori 3,3,0x1
        blr

The second branch and two zero extend are unnecessary. If it returns a integer,
the code seems good.

//test1.c
int foo (int a, int b)
{
  if (a > 2)
    return 0;
  if (b < 10)
    return 1;
  return 1;
}

//assembly with trunk
        li 9,1
        cmpwi 0,3,2
        isel 3,0,9,1
        blr

Reply via email to