www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7953] New: DMD Error: variable r used before set when compiling with -O

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7953

           Summary: DMD Error: variable r used before set when compiling
                    with -O
           Product: D
           Version: D2
          Platform: x86_64
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: suicidenet xited.de



When compiling this code with dmd -O it says:
test.d(55) Error: variable r used before set
i might have overlooked something, but shouldn't that compile?
dmd 2.059 here.


import std.stdio;
import std.math;
import core.simd;
import std.datetime;
import std.conv;

/**
Benchmarks:


suicide zoaHTPC /media/code $ dmd test.d
_VEC: [TickDuration(2014413920)]
SIMD: [TickDuration(2057610817)]
suicide zoaHTPC /media/code $ dmd test.d -O
_VEC: [TickDuration(1589025986)]
SIMD: [TickDuration(2050198165)]
suicide zoaHTPC /media/code $ dmd test.d -O -release
_VEC: [TickDuration(1738538836)]
SIMD: [TickDuration(1172608340)]
suicide zoaHTPC /media/code $ dmd test.d -O -release -inline
_VEC: [TickDuration(1570424587)]
SIMD: [TickDuration(1184942170)]
suicide zoaHTPC /media/code $ dmd test.d -O -release -noboundscheck
_VEC: [TickDuration(752330929)]
SIMD: [TickDuration(1128528117)]

*/


 string gen(int D) {
        string s;
        for(size_t i = 0; i < D-1; i+=4)
        {
            s ~= "v1.array = a1["~to!string(i)~".."~to!string(i+4)~"];";
            s ~= "v2.array = a2["~to!string(i)~".."~to!string(i+4)~"];";
            s ~= "r = __simd(XMM.ADDPS, v1,v2);";            


            //~ s ~= "res["~to!string(i)~".."~to!string(i+4)~"] = r.array;";
            s ~= "res.ptr["~to!string(i)~"] = r.ptr["~to!string(i)~"];";
            s ~= "res.ptr["~to!string(i+1)~"] = r.ptr["~to!string(i+1)~"];";
            s ~= "res.ptr["~to!string(i+2)~"] = r.ptr["~to!string(i+2)~"];";
            s ~= "res.ptr["~to!string(i+3)~"] = r.ptr["~to!string(i+3)~"];";
        }
        return s;
    }

T[D] simdAdd(T, int D)(T[D] a1, T[D] a2) {
    T[D] res;
    float4 v1;
    float4 v2;
    float4 r;

   //writeln(gen(D));
    mixin(gen(D));
    return res;
}

T[D] addV(T, int D)(T[D] a1, T[D] a2) {
    T[D] r;
    //foreach(x;0..10)
        foreach(i;0..D)
            r[i] = a1[i]+a2[i];
    return r;
}


void main()
{
    float[8] v1 = [1,2,3,4,1,2,3,4];
    float[8] v2 = [1,2,3,4,1,2,3,4];
    void test1(){addV(v1,v2);}
    void test2(){simdAdd(v1,v2);}

   // test2();
    //~ writeln("STD: ",
benchmark!(addS!(int,4)([1,2,3,4],[1,2,3,4]))(10_000_000));
    writeln("_VEC: ", benchmark!(test1)(10_000_000));
    writeln("SIMD: ", benchmark!(test2)(10_000_000));
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 20 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7953




first one:
suicide zoaHTPC /media/code $ dmd test.d -release -noboundscheck -O
test.d(55): Error: variable r used before set


another one:
suicide zoaHTPC /media/code $ dmd test.d -release -noboundscheck -O -inline
/usr/include/phobos2/std/datetime.d(29600): Error: variable std.path.sep is
depr
ecated
/usr/include/phobos2/std/datetime.d(29601): Error: variable std.path.sep is
depr
ecated
/usr/include/phobos2/std/path.d(2715): Error: alias std.path.onOutOfMemoryError
is deprecated

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 20 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7953


SomeDude <lovelydear mailmetrash.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |lovelydear mailmetrash.com



PDT ---
Please reduce your code to the minimum that shows the behaviour.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 21 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7953




PDT ---
I've reduced the test case to this:

import core.simd;
import std.conv;

 string gen(int D) {
        string s;
        s ~= "r = __simd(XMM.ADDPS, v1,v2);";
        return "res.ptr["~to!string(0)~"] = r.ptr["~to!string(0)~"];";
    }

T[D] simdAdd(T, int D)(T[D] a1, T[D] a2) {
    T[D] res;
    float4 r;
    mixin(gen(D));
    return res;
}

void main()
{
    float[8] v1 = [1,2,3,4,1,2,3,4];
    float[8] v2 = [1,2,3,4,1,2,3,4];
    simdAdd(v1,v2);
}

but I can't reproduce the error message, so maybe I've overlooked something.
However, interestingly, this compiles with -O flag and crashes the compiler
without.

PS E:\DigitalMars\dmd2\samples> rdmd bug.d
Internal error: ..\ztc\cg87.c 1699
PS E:\DigitalMars\dmd2\samples> rdmd -O bug.d
PS E:\DigitalMars\dmd2\samples>

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 21 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7953




PDT ---

 I've reduced the test case to this:
 
 ...
 
 but I can't reproduce the error message, so maybe I've overlooked something.
 However, interestingly, this compiles with -O flag and crashes the compiler
 without.
 
 PS E:\DigitalMars\dmd2\samples> rdmd bug.d
 Internal error: ..\ztc\cg87.c 1699
 PS E:\DigitalMars\dmd2\samples> rdmd -O bug.d
 PS E:\DigitalMars\dmd2\samples>
The ICE may be related to issue 7951. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Apr 21 2012