-
Bug
-
Resolution: Fixed
-
Medium
-
Code Generation Tools
-
CODEGEN-10915
-
-
-
default
-
CLA floating point ternary expressions returning negation may generate invalid results for --opt_level=2 or higher when if-conversion optimization is triggered.
Below example code generates incorrect results when compiled at --opt_level=2 or higher
and if-conversion optimization is triggered:
res[0] = (p > n) ? p : -n;
res[0] = (p > n) ? -p : n;
Below if/then cases instead generate correct code due to not if-converting:
if (p>n) res[0] = p; else res[0] = -n;
if (p>n) res[0] = -p; else res[0] = n;
No errors with below assembly without if-conversion:
;*** 10 ----------------------- p = a;
;*** 18 ----------------------- C$1 = b;
;*** 18 ----------------------- if ( p > C$1 ) goto g3;
MMOV32 MR0,@a
MMOV32 MR1,@b
MCMPF32 MR0,MR1
MNOP
MNOP
MNOP
MBCNDD $C$L1,GT
MNOP
MNOP
MNOP
Bug occurs with below assembly with if-conversion conditional execution:
;*** 10 ----------------------- p = a;
;*** 12 ----------------------- C$2 = b;
;*** 12 ----------------------- (p > C$2) ? (S$1 = p) : (S$1 = -C$2);
;*** 12 ----------------------- res[0] = S$1;
;*** ----------------------- return;
MMOV32 MR0,@a
MMOV32 MR1,@b
MCMPF32 MR0,MR1
MNEGF32 MR0,MR1,LEQ ; conditional execution from if-conversion
MMOV32 @res,MR0
MNOP
MNOP