File tree Expand file tree Collapse file tree 4 files changed +44
-3
lines changed Expand file tree Collapse file tree 4 files changed +44
-3
lines changed Original file line number Diff line number Diff line change 1
1
Version 6.6.2
2
2
- Added warning (-Warray-index) for constant array indices out of bounds
3
3
- Allow warnings and optimizations to be turned off with a `no-` prefix (so `warn(no-init-vars)` is like `warn(!init-vars)`).
4
+ - Added some peephole optimizations to remove unnecessary sign extension
4
5
5
6
Version 6.6.1
6
7
- Changed type of `dat` array in C++ output to `unsigned char`
Original file line number Diff line number Diff line change
1
+ pub main
2
+ coginit(0, @entry, 0)
3
+ dat
4
+ org 0
5
+ entry
6
+
7
+ _blah
8
+ rdword _var01, arg01
9
+ and _var01, #7
10
+ wrword _var01, arg01
11
+ _blah_ret
12
+ ret
13
+
14
+ COG_BSS_START
15
+ fit 496
16
+ org COG_BSS_START
17
+ _var01
18
+ res 1
19
+ arg01
20
+ res 1
21
+ fit 496
Original file line number Diff line number Diff line change
1
+ void blah (short * x ) {
2
+ * x &= 7 ;
3
+ }
Original file line number Diff line number Diff line change @@ -1030,9 +1030,25 @@ CheckSimpleIncrementLoop(AST *stmt)
1030
1030
} else {
1031
1031
return ;
1032
1032
}
1033
- if (!AstMatchName (updateVar , condtest -> left ))
1034
- return ;
1035
-
1033
+ if (!AstMatchName (updateVar , condtest -> left )) {
1034
+ // special case sign extension
1035
+ bool isOK = false;
1036
+ if (condtest -> left && condtest -> left -> kind == AST_OPERATOR && (condtest -> left -> d .ival == K_SIGNEXTEND || condtest -> left -> d .ival == K_ZEROEXTEND ) ) {
1037
+ if (IsConstExpr (condtest -> left -> right ) && AstMatchName (updateVar , condtest -> left -> left ) && IsConstExpr (finalValue )) {
1038
+ int32_t finalVal = EvalConstExpr (finalValue );
1039
+ int32_t extendVal = EvalConstExpr (condtest -> left -> right );
1040
+ extendVal = 1 <<(extendVal & 0x1f );
1041
+ if (condtest -> left -> d .ival == K_SIGNEXTEND ) {
1042
+ extendVal = extendVal >> 1 ;
1043
+ }
1044
+ isOK = (finalVal >= 0 ) && (finalVal < extendVal );
1045
+ }
1046
+ }
1047
+ if (!isOK ) {
1048
+ return ;
1049
+ }
1050
+ }
1051
+
1036
1052
/* check that the update is i++, and the variable is not used anywhere else */
1037
1053
while (update -> kind == AST_SEQUENCE ) {
1038
1054
if (AstUsesName (update -> right , updateVar )) {
You can’t perform that action at this time.
0 commit comments