http://d.puremagic.com/issues/show_bug.cgi?id=5812

           Summary: Power expression optimisation: constant fold (x^^0) =
                    1
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nob...@puremagic.com
        ReportedBy: ibuc...@ubuntu.com


--- Comment #0 from Iain Buclaw <ibuc...@ubuntu.com> 2011-04-03 18:06:47 PDT ---
CTFE testcases (that currently fail)

  const x = 3;
  static assert((7 ^^ 0) == 1);
  static assert((7 ^^ 0.0) == 1);
  static assert((x ^^ 0) == 1);
  static assert((x ^^ 0.0) == 1);




Patch:

--- dmd.orig/expression.c       2011-02-18 01:15:38.000000000 +0000
+++ dmd/expression.c    2011-04-04 02:05:38.631620650 +0100
@@ -10302,6 +10302,15 @@ Expression *PowExp::semantic(Scope *sc)
             e = e->semantic(sc);
             return e;
         }
+        // Replace x ^^ 0 or x^^0.0 by (x, 1)
+        if ((e2->op == TOKint64 && e2->toInteger() == 0) ||
+                (e2->op == TOKfloat64 && e2->toReal() == 0.0))
+        {
+            typeCombine(sc);
+            e = new CommaExp(loc, e1, new IntegerExp(loc, 1, Type::tint32));
+            e = e->semantic(sc);
+            return e;
+        }
         // Replace -1 ^^ x by (x&1) ? -1 : 1, where x is integral
         if (e2->type->isintegral() && e1->op == TOKint64 &&
(sinteger_t)e1->toInteger() == -1L)
         {



Feel free to improve it.

Regards

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------

Reply via email to