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

            Bug ID: 121470
           Summary: (unsigned short)0x8000 is expanded incorrectly
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: segher at gcc dot gnu.org
  Target Milestone: ---

Created attachment 62086
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=62086&action=edit
testcase

This testcase:

===
void f(void) { asm("ori 0,0,%0" : : "n"((unsigned short)0x8000)); }
void g(void) { asm("ori 0,0,%0" : : "n"(0x8000)); }
===

results in

f:        ori 0,0,-32768
g:        ori 0,0,32768

f() is incorrect, of course.

It is expand that is doing it.  Before expand we have (from 271t.optimized):

  __asm__ __volatile__("ori 0,0,%0" :  : "n" 32768);

which is just fine.  But then expand somehow decides to do

;; __asm__ __volatile__("ori 0,0,%0" :  : "n" 32768);

(insn 5 4 0 (parallel [
            (asm_operands/v ("ori 0,0,%0") ("") 0 [
                    (const_int -32768 [0xffffffffffff8000])
                ]
                 [
                    (asm_input:HI ("n") o8.c:1)
                ]
                 [] o8.c:1)
            (clobber (reg:SI 98 ca))
        ]) "o8.c":1:16 -1
     (nil))

(and for g() it doesn't do any such sillyness).

Reply via email to