This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Need advice: x86 redudant compare to zero



On Oct 13, 2005, at 7:41 PM, Evan Cheng wrote:


Hi,

Here is a bits of code from bzip2:

#define mswap(zz1, zz2) { int zztmp = zz1; zz1 = zz2; zz2 = zztmp; }

void foo(int unLo, int unHi, int ltLo, int *ptr, char *block, int med, int d, int n) {

  while (1) {
    if (unLo > unHi) break;
    n = ((int)block[ptr[unLo]+d]) - med;
    if (n == 0) {
      mswap(ptr[unLo], ptr[ltLo]);
      ltLo++; unLo++; continue;
    };
    if (n >  0) break;
    unLo++;
  }
}


PowerPC describes the pattern were we don't need the result of n after a
compare as:
(define_insn ""
[(set (match_operand:CC 0 "cc_reg_operand" "=x,?y")
(compare:CC (minus:P (match_operand:P 1 "gpc_reg_operand" "r,r")
(match_operand:P 2 "gpc_reg_operand" "r,r"))
(const_int 0)))
(clobber (match_scratch:P 3 "=r,r"))]
"TARGET_POWERPC"
"@
subf. %3,%2,%1
#"
[(set_attr "type" "fast_compare")
(set_attr "length" "4,8")])



So something like (not tested):


(define_insn ""
[(set (reg FLAGS_REG)
(compare (minus:P (match_operand:SI 1 "nonimmediate_operand" "0,0")
(match_operand:SI 2 "general_operand" "ri,rm"))
(const_int 0)))
(clobber (match_scratch:SI 1 "=r"))]
"ix86_match_ccmode (insn, CCGOCmode)
&& ix86_binary_operator_ok (MINUS, SImode, operands)"
"sub{l}\t{%2, %0|%0, %2}"
[(set_attr "type" "alu")
(set_attr "mode" "SI")])


Maybe adding a pattern like that, will work?

You most likely would like to "steal" other patterns like that from the rs6000
backend.


Thanks,
Andrew Pinski


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]