Hi,

   could a gatekeeper please help review the fix for bug963?(
https://bugs.open64.net/show_bug.cgi?id=963)

bug case:
static inline __attribute__((always_inline)) __attribute__((pure)) unsigned
char __static_cpu_has(unsigned short bit)
{
  unsigned char flag;

  asm volatile("1: movb $0,%0\n"
        "2:\n"
        ".section .altinstructions,\"a\"\n"
        " " ".balign 8" " " "\n"
        " " ".quad" " " "1b\n"
        " " ".quad" " " "3f\n"
        " .word %P1\n"
        " .byte 2b - 1b\n"
        " .byte 4f - 3f\n"
        ".previous\n"
        ".section .discard,\"aw\",@progbits\n"
        " .byte 0xff + (4f-3f) - (2b-1b)\n"
        ".previous\n"
        ".section .altinstr_replacement,\"ax\"\n"
        "3: movb $1,%0\n"
        "4:\n"
        ".previous\n"
        : "=qm" (flag) : "i" (bit));
  return flag;

}

unsigned char f(void){
  return __static_cpu_has(24) ;
}

opencc -c bug963 <https://bugs.open64.net/show_bug.cgi?id=963>.c -O2
"bug963 <https://bugs.open64.net/show_bug.cgi?id=963>.c", line 5: Error:
Invalid 'asm' constrain : Cannot find immediate
operand for ASM

Analysis:

24 is a constant value for bit in the caller, when __static_cpu_has is
inlined to f, the bit value is failed to copy propagated into the
ASM_INPUT, this is because we now only enable var->var copy propagation for
ASM_INPUT, for the case of "i" constraint, we need do such cprop.

gcc internals
(http://gcc.gnu.org/onlinedocs/gccint/Simple-Constraints.html)
documents the "i" constraint as below, it is a target-independent
constraint.

`i' An immediate integer operand (one with constant value) is allowed. This
includes symbolic constants whose values will be known only at assembly
time or later.

suggested patch:
osprey/be/opt/opt_prop.cxx    -- 966f38e..8cc897c 100644
--- a/osprey/be/opt/opt_prop.cxx
+++ b/osprey/be/opt/opt_prop.cxx
@@ -1511,6 +1511,14 @@ COPYPROP::Copy_propagate_cr(CODEREP *x, BB_NODE
*curbb,
               CODEREP *possible_prop = Copy_propagate_cr(x->Opnd(i),
curbb, inside_cse, in_array);
               if (possible_prop && possible_prop->Kind() ==
x->Opnd(i)->Kind())
                 expr = possible_prop;
+              // open64.net bug963. If the Asm_input constraint is "i",
i.e, required immediate
+              // and the possible propagation is also a var, we do this
propagation on demand.
+              else if (possible_prop &&
+                       (possible_prop->Kind() == CK_CONST ||
+                        possible_prop->Kind() == CK_RCONST) &&
+
!strncmp(ST_name(&St_Table[x->Asm_constraint()]),"i",1)) {
+                expr = possible_prop;
+              }
               else {
                 x->Opnd(i)->Set_flag(CF_DONT_PROP);
                 expr = NULL;
Could a gatekeeper please help a review? thanks in advance.


Regards
Gang
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Open64-devel mailing list
Open64-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/open64-devel

Reply via email to