<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    Hi Anastasia,<br>
    <br>
    I appreciate your response. I think we need to keep
    "ScalarExprEmitter::VisitAsTypeExpr" between vec3 and vec4, as we
    want to maintain the features of the OpenCL source language. If llvm
    has intrinsic function on IR for the __builtin_astype, we could
    generate it and llvm's CodeGen could handle it. I have found other
    location for vec3 and it is "CodeGenFunction::EmitStoreOfScalar". I
    have simply added a clang's CodeGen Option to preseve vec3. I have
    attached the diff file and a test. If I missed something, please let
    me know.<br>
    <br>
    Thanks,<br>
    <br>
    JinGu Kang<br>
    <br>
    <div class="moz-cite-prefix">On 08/03/17 13:05, Anastasia Stulova
      wrote:<br>
    </div>
    <blockquote
cite="mid:DB6PR0802MB22964BB5072EF08F0B54E7F8F02E0@DB6PR0802MB2296.eurprd08.prod.outlook.com"
      type="cite">
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      <meta name="Generator" content="Microsoft Word 14 (filtered
        medium)">
      <style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";
        color:black;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
      <div class="WordSection1">
        <p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">I
            think the problem is that the borderline for IR being target
            independent is very vague in general. In this case
            specifically the issue is that the Spec is very explicit
            about threating this as 4 element aligned type. However, I
            agree this lowering could be done later as well. The
            approach to condition this on the Target property sounds
            reasonable. I think we have other places in Clang where vec3
            is threated as vec4 (e.g.
            ScalarExprEmitter::VisitAsTypeExpr). Those would have to be
            handled too. Feel free to propose a prototype.<o:p></o:p></span></p>
        <p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
        <p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Cheer,<o:p></o:p></span></p>
        <p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Anastasia<o:p></o:p></span></p>
        <p class="MsoNormal"><span
style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
        <div>
          <div style="border:none;border-top:solid #B5C4DF
            1.0pt;padding:3.0pt 0cm 0cm 0cm">
            <p class="MsoNormal"><b><span
style="font-size:10.0pt;font-family:"Tahoma","sans-serif";color:windowtext"
                  lang="EN-US">From:</span></b><span
style="font-size:10.0pt;font-family:"Tahoma","sans-serif";color:windowtext"
                lang="EN-US"> cfe-dev
                [<a class="moz-txt-link-freetext" href="mailto:cfe-dev-bounces@lists.llvm.org">mailto:cfe-dev-bounces@lists.llvm.org</a>]
                <b>On Behalf Of </b><a class="moz-txt-link-abbreviated" href="mailto:jingu@codeplay.com">jingu@codeplay.com</a> via cfe-dev<br>
                <b>Sent:</b> 08 March 2017 11:01<br>
                <b>To:</b> <a class="moz-txt-link-abbreviated" href="mailto:aleksey.bader@gmail.com">aleksey.bader@gmail.com</a><br>
                <b>Cc:</b> '<a class="moz-txt-link-abbreviated" href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>'
                (<a class="moz-txt-link-abbreviated" href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>)<br>
                <b>Subject:</b> Re: [cfe-dev] Question about
                "CodeGenFunction::EmitLoadOfScalar" with vector type of
                3 elements<o:p></o:p></span></p>
          </div>
        </div>
        <p class="MsoNormal"><o:p> </o:p></p>
        <p class="MsoNormal" style="margin-bottom:12.0pt">Hi Alexey,<br>
          <br>
          I appreciate your response. My colleague and I are
          implementing a transformation pass between LLVM IR and another
          IR and we want to keep the 3-component vector types in our
          target IR. As you mentioned, the 4-component vector type
          conversion code is not problem. But I usually expect clang
          generates more target independent LLVM IR except target
          specific properties like calling convention, memory layout of
          variables, etc. clang can keep the 3-component vector type
          operations and llvm codegen can handle them according to
          target. At present, we're having to undo Clang's
          transformation of vec3 -> vec4, to recreate the original
          type information, which is unfortunate. Would it be possible
          to add an option to control the behaviour?<br>
          <br>
          Thanks,<br>
          <br>
          JinGu Kang<br>
          <br>
          <o:p></o:p></p>
        <div>
          <p class="MsoNormal">On 07/03/17 18:19, <a
              moz-do-not-send="true"
              href="mailto:aleksey.bader@gmail.com">
              aleksey.bader@gmail.com</a> wrote:<o:p></o:p></p>
        </div>
        <blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
          <div>
            <p class="MsoNormal">Hi JinGu, <o:p></o:p></p>
            <div>
              <p class="MsoNormal"><o:p> </o:p></p>
            </div>
            <div>
              <p class="MsoNormal">I don't think it should be a problem
                for OpenCL. 3-component vector is aligned as 4-component
                vector (see section 6.1.5 "Alignment of Type" of OpenCL
                C kernel language specification v2.0).<o:p></o:p></p>
            </div>
            <div>
              <p class="MsoNormal">AFAIK, almost all existing OpenCL
                compilers are based on clang and there seems to be no
                problems with handling load/store operations this way.<o:p></o:p></p>
            </div>
            <div>
              <p class="MsoNormal">Could you elaborate on the case where
                this approach doesn't work?<o:p></o:p></p>
            </div>
            <div>
              <p class="MsoNormal"><o:p> </o:p></p>
            </div>
            <div>
              <p class="MsoNormal">Thanks,<o:p></o:p></p>
            </div>
            <div>
              <p class="MsoNormal">Alexey<o:p></o:p></p>
            </div>
          </div>
          <div>
            <p class="MsoNormal"><o:p> </o:p></p>
            <div>
              <p class="MsoNormal">On Mon, Mar 6, 2017 at 6:47 PM, <a
                  moz-do-not-send="true"
                  href="mailto:jingu@codeplay.com">
                  jingu@codeplay.com</a> via cfe-dev <<a
                  moz-do-not-send="true"
                  href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>>
                wrote:<o:p></o:p></p>
              <p class="MsoNormal">Hi All,<br>
                <br>
                <br>
                I have a question about
                "CodeGenFunction::EmitLoadOfScalar". I am compiling code
                with vector type of 3 elements like int3 or float3.
                Clang converts the vector load to different vector load
                with 4 element vector type because there is code on
                "CodeGenFunction::EmitLoadOfScalar" as follows:<br>
                <br>
                1312   // For better performance, handle vector loads
                differently.<br>
                1313   if (Ty->isVectorType()) {<br>
                1314     const llvm::Type *EltTy =
                Addr.getElementType();<br>
                1315<br>
                1316     const auto *VTy =
                cast<llvm::VectorType>(EltTy);<br>
                1317<br>
                1318     // Handle vectors of size 3 like size 4 for
                better performance.<br>
                1319     if (VTy->getNumElements() == 3) {<br>
                1320<br>
                1321       // Bitcast to vec4 type.<br>
                1322       llvm::VectorType *vec4Ty =
                llvm::VectorType::get(VTy->getElementType(),<br>
                1323                                                   
                      4);<br>
                1324       Address Cast =
                Builder.CreateElementBitCast(Addr, vec4Ty,
                "castToVec4");<br>
                1325       // Now load value.<br>
                1326       llvm::Value *V = Builder.CreateLoad(Cast,
                Volatile, "loadVec4");<br>
                <br>
                4 element vector load could generate aligned vector load
                in the end and it would be better in usual. But it is
                not good for other target or language like OpenCL which
                supports 3 element vector type natively. Can we consider
                this situation on "CodeGenFunction::EmitLoadOfScalar"
                like this "if (!getLangOpts().OpenCL)" or with target
                specific property on TargetCodeGenInfo?<br>
                <br>
                If I missed something, please let me know.<br>
                <br>
                Thanks,<br>
                JinGu Kang<br>
                <br>
                _______________________________________________<br>
                cfe-dev mailing list<br>
                <a moz-do-not-send="true"
                  href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
                <a moz-do-not-send="true"
                  href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev"
                  target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><o:p></o:p></p>
            </div>
            <p class="MsoNormal"><o:p> </o:p></p>
          </div>
        </blockquote>
        <p class="MsoNormal"><o:p> </o:p></p>
      </div>
    </blockquote>
    <br>
  </body>
</html>