-
Type:
Bug
-
Resolution: Fixed
-
Priority:
Medium
-
Code Generation Tools
-
CODEGEN-12562
-
-
-
default
-
For pointer expressions with an unsigned 16bit int variable plus/minus a
constant, eg: (uint16 + k), that also have an implicit cast to 32bit signed
int, eg: (int32)(uint16 + k), the optimizer will incorrectly push the
cast to within the expression: ((int32)uint16 + k)
With option, --opt_level=2, this C code:
MyStruct *struct = MyStructPtrs[uint16 - constant];
Incorrectly optimizes to below:
; StructPtr = MyStructPtrs[(long)MyStructID+22284];
MOV ACC,AL << 1 ; [CPU_ALU] |24|
ADDL ACC,@||MyStructPtrs|| ; [CPU_ALU] |24|
MOVL XAR5,ACC ; [CPU_ALU] |24|
MOVL XAR0,#44568 ; [CPU_ALU] |24|
MOVL ACC,*+XAR5[AR0] ; [CPU_ALU] |24|
MOVL *-SP[6],ACC ; [CPU_ALU] |24|
And here's what should be generated instead:
; StructPtr = MyStructPtrs[(long)(MyStructID+22284u)];
MOV AL,#22284 ; [CPU_ALU] |24|
ADD AL,*-SP[13] ; [CPU_ALU] |24|
MOV ACC,AL << 1 ; [CPU_ALU] |24|
ADDL ACC,@||MyStructPtrs|| ; [CPU_ALU] |24|
MOVL XAR5,ACC ; [CPU_ALU] |24|
MOVL ACC,*+XAR5[0] ; [CPU_ALU] |24|
MOVL *-SP[6],ACC ; [CPU_ALU] |24|