Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
riscv-gcc-1
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
riscv-gcc-1
Commits
d59b3b67
Commit
d59b3b67
authored
Nov 14, 2001
by
Roger Sayle
Committed by
Richard Henderson
Nov 14, 2001
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
* fold-const.c (fold): Optimize strlen comparisons against zero.
From-SVN: r47029
parent
81bc01c2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
0 deletions
+31
-0
gcc/ChangeLog
+4
-0
gcc/fold-const.c
+27
-0
No files found.
gcc/ChangeLog
View file @
d59b3b67
2001
-
11
-
14
Roger
Sayle
<
roger
@eyesopen
.
com
>
*
fold
-
const
.
c
(
fold
)
:
Optimize
strlen
comparisons
against
zero
.
2001
-
11
-
14
David
O
'
Brien
<
obrien
@FreeBSD
.
org
>
2001
-
11
-
14
David
O
'
Brien
<
obrien
@FreeBSD
.
org
>
*
config
.
gcc
(
sparc64
-
wrs
-
vxworks
*
,
sparc
-*-
netbsd
*
,
sparc
-*-
openbsd
*
,
*
config
.
gcc
(
sparc64
-
wrs
-
vxworks
*
,
sparc
-*-
netbsd
*
,
sparc
-*-
openbsd
*
,
...
...
gcc/fold-const.c
View file @
d59b3b67
...
@@ -6899,6 +6899,33 @@ fold (expr)
...
@@ -6899,6 +6899,33 @@ fold (expr)
fold
(
build
(
code
,
type
,
imag0
,
imag1
))));
fold
(
build
(
code
,
type
,
imag0
,
imag1
))));
}
}
/* Optimize comparisons of strlen vs zero to a compare of the
first character of the string vs zero. To wit,
strlen(ptr) == 0 => *ptr == 0
strlen(ptr) != 0 => *ptr != 0
Other cases should reduce to one of these two (or a constant)
due to the return value of strlen being unsigned. */
if
((
code
==
EQ_EXPR
||
code
==
NE_EXPR
)
&&
integer_zerop
(
arg1
)
&&
TREE_CODE
(
arg0
)
==
CALL_EXPR
&&
TREE_CODE
(
TREE_OPERAND
(
arg0
,
0
))
==
ADDR_EXPR
)
{
tree
fndecl
=
TREE_OPERAND
(
TREE_OPERAND
(
arg0
,
0
),
0
);
tree
arglist
;
if
(
TREE_CODE
(
fndecl
)
==
FUNCTION_DECL
&&
DECL_BUILT_IN
(
fndecl
)
&&
DECL_BUILT_IN_CLASS
(
fndecl
)
!=
BUILT_IN_MD
&&
DECL_FUNCTION_CODE
(
fndecl
)
==
BUILT_IN_STRLEN
&&
(
arglist
=
TREE_OPERAND
(
arg0
,
1
))
&&
TREE_CODE
(
TREE_TYPE
(
TREE_VALUE
(
arglist
)))
==
POINTER_TYPE
&&
!
TREE_CHAIN
(
arglist
))
return
fold
(
build
(
code
,
type
,
build1
(
INDIRECT_REF
,
char_type_node
,
TREE_VALUE
(
arglist
)),
integer_zero_node
));
}
/* From here on, the only cases we handle are when the result is
/* From here on, the only cases we handle are when the result is
known to be a constant.
known to be a constant.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment