https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83272
Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Severity|normal |enhancement Last reconfirmed| |2021-08-14 Status|UNCONFIRMED |NEW Ever confirmed|0 |1 --- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> --- (In reply to Mason from comment #2) > Anyway, I may have oversimplified the testcase. Consider this one: > > char foo(unsigned char *p) > { > static const char map[16] = "wxyz"; > return map[*p / 16]; > } For this case we start in before combine: (insn 8 7 9 2 (parallel [ (set (reg:QI 89) (lshiftrt:QI (reg:QI 90 [ *p_5(D) ]) (const_int 4 [0x4]))) (clobber (reg:CC 17 flags)) ]) "/app/example.cpp":5:16 729 {*lshrqi3_1} (expr_list:REG_DEAD (reg:QI 90 [ *p_5(D) ]) (expr_list:REG_UNUSED (reg:CC 17 flags) (nil)))) (insn 9 8 10 2 (set (reg:SI 91) (zero_extend:SI (reg:QI 89))) "/app/example.cpp":5:16 141 {*zero_extendqisi2} (expr_list:REG_DEAD (reg:QI 89) (nil))) (insn 10 9 11 2 (set (reg:DI 92) (sign_extend:DI (reg:SI 91))) "/app/example.cpp":5:20 145 {*extendsidi2_rex64} (expr_list:REG_DEAD (reg:SI 91) (nil))) after: (insn 8 7 9 2 (parallel [ (set (reg:QI 89) (lshiftrt:QI (reg:QI 90 [ *p_5(D) ]) (const_int 4 [0x4]))) (clobber (reg:CC 17 flags)) ]) "/app/example.cpp":5:16 729 {*lshrqi3_1} (expr_list:REG_DEAD (reg:QI 90 [ *p_5(D) ]) (expr_list:REG_UNUSED (reg:CC 17 flags) (nil)))) (note 9 8 10 2 NOTE_INSN_DELETED) (insn 10 9 11 2 (parallel [ (set (reg:DI 92) (and:DI (subreg:DI (reg:QI 89) 0) (const_int 15 [0xf]))) (clobber (reg:CC 17 flags)) ]) "/app/example.cpp":5:20 498 {*anddi_1} (expr_list:REG_UNUSED (reg:CC 17 flags) (expr_list:REG_DEAD (reg:QI 89) (nil)))) And that is due to knowing the nonzero bits of reg 89 (after the shift): Trying 9 -> 10: 9: r91:SI=zero_extend(r89:QI) REG_DEAD r89:QI 10: r92:DI=sign_extend(r91:SI) REG_DEAD r91:SI Successfully matched this instruction: (set (reg:DI 92) (and:DI (subreg:DI (reg:QI 89) 0) (const_int 15 [0xf]))) allowing combination of insns 9 and 10 original costs 4 + 4 = 8 replacement cost 4 deferring deletion of insn with uid = 9. modifying insn i3 10: {r92:DI=r89:QI#0&0xf;clobber flags:CC;} REG_UNUSED flags:CC REG_DEAD r89:QI deferring rescan insn with uid = 10. ------- CUT ----- So combining is over using the nonzero bits sometimes.