Rate This Document
Findability
Accuracy
Completeness
Readability

-fchrec-mul-fold-strict-overflow

Description

The multiplication folding optimization can correctly handle multiplication operations that may cause undefined behavior, such as integer overflow.

Usage

Enable the optimization level -O2 or higher and add the compilation option -fchrec-mul-fold-strict-overflow.

Result

The test case is as follows:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
typedef int int32_t __attribute__((mode (__SI__)));
 
void bar (int32_t);
 
void
foo ()
{
    int32_t index = 0;
 
    for (index; index <= 10; index--)
    /* Result of the following multiply will overflow
       when converted to signed int32_t.  */
    bar ((0xcafe + index) * 0xdead);
}

Test command:

1
gcc -O2 -fdisable-tree-ethread -fchrec-mul-fold-strict-overflow test.c -S -o test.s
Figure 1 Option disabled
Figure 2 Option enabled