<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Compiler error when optimising loop in Intel® oneAPI DPC++/C++ Compiler</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/Compiler-error-when-optimising-loop/m-p/1670760#M4315</link>
    <description>Thanks a bunch for that. I have never heard about strict aliasing before, I just assumed that memory contents were mine to interpret as I pleased.&lt;BR /&gt;&lt;BR /&gt;I have loads of mixed float and int arrays as well, which I see contravene that rule. I'm going to need that compiler flag!&lt;BR /&gt;</description>
    <pubDate>Thu, 27 Feb 2025 18:11:17 GMT</pubDate>
    <dc:creator>ChristopherBell</dc:creator>
    <dc:date>2025-02-27T18:11:17Z</dc:date>
    <item>
      <title>Compiler error when optimising loop</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/Compiler-error-when-optimising-loop/m-p/1669511#M4313</link>
      <description>&lt;P&gt;I'm using the 2023 OneAPI C++ compiler to rebuild some existing software that we have previously built with the 2019 Intel compiler.&amp;nbsp; I am seeing an error in a loop which "expands" an array of 4 byte integers to become 8 byte integers in the same storage space.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Qualitatively it works like this:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Declare an array long enough to hold N 8 byte (long long) integers&lt;/LI&gt;&lt;LI&gt;Read N 4 byte (int) integers into the bottom half of this&lt;/LI&gt;&lt;LI&gt;Working from the end of the array backwards copy each 4 byte integer into the appropriate 8 byte slot by array index.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;The coding that matters could be written:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;long long *buff_8;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// Dynamically allocated space to hold N long longs&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;int&amp;nbsp; &amp;nbsp;*buff_4 = (int *)buff_8;&amp;nbsp; &amp;nbsp;// Interpret this space as 4 byte integers&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;... populate buff_4[] with an array of N 4 byte integer values&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier" size="2"&gt;for(i=N-1; i&amp;gt;=0; i--) buff_8[i] = buff_4[i];&amp;nbsp; &amp;nbsp; &amp;nbsp;// Copy the numbers to long long format&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have attached two very simple files which show the problem:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;main.c sets up, populates and tests the storage&lt;/LI&gt;&lt;LI&gt;sub.c performs the I4 =&amp;gt; I8 copy&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;To reproduce this just create a console C project of these two files, nothing fancy required, use a Release build to turn on optimisation (I used /O2) and turn off interprocedural optimisation.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Working on Windows (in VS2022) if I perform the copy in a separate function in a separate file and&amp;nbsp; turn interprocedural optimisation to multiifile (/Qipo) this works fine, if I turn it off it fails and I get zeros.&amp;nbsp; Interestingly if I use Intel 2019 compilers the opposite is true: it fails when using /Qipo but works without.&lt;BR /&gt;&lt;BR /&gt;I also tried on Linux where I got different behaviour: the Intel 2019 compiler failed when I wrote this as a single function, but worked if I put a #pragma novector before the copy loop, the OneAPI compiler has - so far - worked OK.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We see this problem in the 2024 compiler as well, haven't tried 2025.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We can solve the problem by isolating that function and using&amp;nbsp; &lt;FONT face="courier new,courier" size="2"&gt;#pragma optimize ("", off)&lt;/FONT&gt; to stop it being optimised, so it is not a show-stopper.&amp;nbsp; But I think it is quite a serious compiler bug.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2025 15:53:44 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/Compiler-error-when-optimising-loop/m-p/1669511#M4313</guid>
      <dc:creator>ChristopherBell</dc:creator>
      <dc:date>2025-02-24T15:53:44Z</dc:date>
    </item>
    <item>
      <title>Re: Compiler error when optimising loop</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/Compiler-error-when-optimising-loop/m-p/1670750#M4314</link>
      <description>&lt;P&gt;Hi, icpx defaults to O2 optimization level, and it assumes code doesn't violate strict aliasing rule. In your code, buff_8 and buff_4 point to the same address, which violates this rule. This issue can be avoided with option "-fno-strict-aliasing".&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Feb 2025 17:30:35 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/Compiler-error-when-optimising-loop/m-p/1670750#M4314</guid>
      <dc:creator>yzh_intel</dc:creator>
      <dc:date>2025-02-27T17:30:35Z</dc:date>
    </item>
    <item>
      <title>Re: Compiler error when optimising loop</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/Compiler-error-when-optimising-loop/m-p/1670760#M4315</link>
      <description>Thanks a bunch for that. I have never heard about strict aliasing before, I just assumed that memory contents were mine to interpret as I pleased.&lt;BR /&gt;&lt;BR /&gt;I have loads of mixed float and int arrays as well, which I see contravene that rule. I'm going to need that compiler flag!&lt;BR /&gt;</description>
      <pubDate>Thu, 27 Feb 2025 18:11:17 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/Compiler-error-when-optimising-loop/m-p/1670760#M4315</guid>
      <dc:creator>ChristopherBell</dc:creator>
      <dc:date>2025-02-27T18:11:17Z</dc:date>
    </item>
  </channel>
</rss>

