Hi,

   Could a gatekeeper please help review the following patch for bug916
http://bugs.open64.net/show_bug.cgi?id=916?

Symptom:
    opencc does not accept the asm constraint like , "i"(&p.v), while gcc
does.

struct T {
  int u;
  int v;
} t;
int main(void)
{
  void * ret__;
  asm volatile ("mov ""%P" "1"",%0" : "=r" (ret__) : "i" (&t.v));
  return 0;
}

hunks below resolve this:
@@ -3493,11 +3495,22 @@ CGTARG_TN_For_Asm_Operand (const char* constraint,
     if (!(load && (WN_operator(load) == OPR_INTCONST ||
                        (WN_operator(load) == OPR_LDA &&
-                        ST_sym_class(WN_st(load)) == CLASS_CONST)))) {
+                        // &var.field is also allowed, bug916 open64.net
+                        (ST_sym_class(WN_st(load)) == CLASS_VAR ||
+                         ST_sym_class(WN_st(load)) == CLASS_CONST))))) {

+    else if (ST_sym_class(WN_st(load)) == CLASS_VAR) {
+      ST *base;
+      INT64 ofst;
+      Base_Symbol_And_Offset_For_Addressing (WN_st(load),
WN_lda_offset(load), &base, &ofst);
+      ret_tn = Gen_Symbol_TN(base,ofst,0);

&t.v can only be instantiated to a symbol TN.

However, it is not done. Interesting part comes. The bug 916-2.c still
fails at O2 or above,

struct u{
  int a;
  void (*f)(void);
} p;
int main(void)
{
  void * ret__;
  asm volatile ("mov %" "1"",%0" : "=r" (ret__) : "i" (&(p.f)));
  asm volatile ("mov %" "1"",%0" : "=r" (ret__) : "i" (&(p.f)));
  return 0;
}

this is because the common sub-expression &p.f is lifted up to a preg by
wopt and the preg is not rematerializable to a Home WN. so
3493    if (load && WN_operator(load)==OPR_LDID &&
WN_class(load)==CLASS_PREG)
3494    {
3495      // immediate could have been put in preg by wopt
3496      load = Preg_Is_Rematerializable(WN_load_offset(load), NULL);
3497    }

make load a null value, which then asserts.

We can't get the associated WN for a preg TN easily. Luckily, TARG_NVISA
already provide a solution although it is enclosed by TARG_NVISA.

in be_symtab.h:

504class BE_PREG {
505private:
506  WN *home_location;
507#ifdef TARG_NVISA
508  WN *lda;
509#endif
510public:
511#ifdef TARG_NVISA
512  BE_PREG(void) : home_location(NULL), lda(NULL)  { }
513#else
514  BE_PREG(void) : home_location(NULL)   { }
515#endif
516  void  Set_home_location(WN *wn)       { home_location = wn; }
517  WN   *Home_location(void) const       { return home_location; }
518#ifdef TARG_NVISA
519  void  Set_lda(WN *wn)    { lda = wn; }
520  WN   *Lda(void) const    { return lda; }
521#endif

we see TARG_NVISA already provide such facility, next we disclose these
parts and filter out those still belongs TARG_NVISA only(i.e, in Find_Lda
and ST_in_share_mem and ST_in_const_mem) , we get things done.

The extra computation is Find_Lda when lowing a preg expression, this does
not introduce much expense.

Test and Valiadation:

please find cases bug916 to bug916-7 at the open64 regression site

Merged with previous constraint_p patch, we build the kernel with no
constrain assertion thrown out.

The whole patch is attached

Would a gatekeeper help a review? thanks very much.


Regards
Gang

Attachment: bug916.patch
Description: Binary data

------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
Open64-devel mailing list
Open64-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/open64-devel

Reply via email to