-
Enhancement
-
Resolution: Implemented
-
Medium
-
Code Generation Tools
-
CODEGEN-7364
-
-
default
-
None automatic. The customer did the transformation by hand to compensate.
-
The compiler didn't do return-value optimisation (copy elision) in cases like the classic two-operand operator+(). The effect is an extra copy and an extra temporary variable.
The attached test case files create a class that contains floating point arrays, and does addition and subtraction operations on those arrays. When results are returns from the add and subtract operations, they are copied from a local to the result location. Instead, the result location should be directly operated on.
To build ...
% cl6x -@options.txt --symdebug:none -s main.cpp matrix2.cpp
Inspect the resulting assembly files. For the add operation in matrix2.asm, this compiler generated comment appears ...
;** 639 ----------------------- (*$P$T0).alloc = *(struct Matrix3x3::_Alloc *)&result; // [3]
This is the copy which should be avoided.