On Wed, Jun 23, 2010 at 4:50 PM, Paolo Bonzini wrote: > On 06/24/2010 01:13 AM, H.J. Lu wrote: >>> >>> I don't understand exactly what the problem was; clearly it couldn't work >>> as >>> long as this pattern was cheating blatantly: >> >> Upper 8bit registers aren't real registers. You can't >> do RA with them. > > Please read what other people write.  I'm saying that you should have used a > HI destination just like you did with your new UNSPEC, which is acceptable. > > The pattern I quoted below used a QI destination; then magically you > attempted to extract bit 8..15 of it with an unspec, or something like that. >  For anything like that the optimizers are going to bite back sooner or > later.  And you'd deserve it. > >>> (define_insn "*divqi3" >>>  [(set (match_operand:QI 0 "register_operand" "=a") >>>        (any_div:QI >>>          (match_operand:HI 1 "register_operand" "0") >>>          (match_operand:QI 2 "nonimmediate_operand" "qm"))) >>> >>> Anyway this patch is IMO much nicer than the first ones, so if Uros is >>> okay >>> I don't think it's useful to pursue a more accurate representation.  Just >>> make sure that REG_EQUAL notes are added to the two extractions. >>> >> >> What are REG_EQUAL notes used for? >> As far as the rest of gcc is concerned, there are no upper 8bit >> registers. But you can access bits 8-15 of HI, SI, >> DI registers via XXX_extract. > > Understood.  Using an unspec is fine for me, even though it's not an > approval.  But that's completely orthogonal to putting a REG_EQUAL note _on > the two regs that you extract out of AX_.  The notes' value should be one of > >   (subreg:QI (udiv:HI (...) (zero_extend (...)))) >   (subreg:QI (div:HI (...) (sign_extend (...)))) >   (subreg:QI (umod:HI (...) (zero_extend (...)))) >   (subreg:QI (mod:HI (...) (sign_extend (...)))) > > But I think that with over ten years of GCC experience you do not need > anyone to tell you this.  In fact, regarding "what are REG_EQUAL notes used > for?" my first thought was RTFM, but anyway: they are used by CSE, fwprop, > GCSE and combine to simplify and eliminate redundant expressions. I am learning new things all the time. Thanks for the pointer. Here is a new patch without UNSPEC. OK for trunk? Thanks. -- H.J. --- gcc/ 2010-06-24 H.J. Lu PR target/44588 * config/i386/i386.md (extract_code): New. (divmodqi4): Likewise. (divmodhiqi3): Likewise. (udivmodhiqi3): Likewise. (divqi3): Remvoved. gcc/testsuite/ 2010-06-24 H.J. Lu PR target/44588 * gcc.target/i386/mod-1.c: New. * gcc.target/i386/umod-1.c: Likewise. * gcc.target/i386/umod-2.c: Likewise. * gcc.target/i386/umod-3.c: Likewise.