Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
llvm-epi-0.8
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Roger Ferrer
llvm-epi-0.8
Commits
464276f8
Commit
464276f8
authored
17 years ago
by
Devang Patel
Browse files
Options
Downloads
Patches
Plain Diff
Avoid unsafe promotion.
llvm-svn: 42149
parent
62fd2b47
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
llvm/lib/Transforms/Scalar/LICM.cpp
+41
-9
41 additions, 9 deletions
llvm/lib/Transforms/Scalar/LICM.cpp
llvm/test/Transforms/LICM/2007-09-17-PromoteValue.ll
+35
-0
35 additions, 0 deletions
llvm/test/Transforms/LICM/2007-09-17-PromoteValue.ll
with
76 additions
and
9 deletions
llvm/lib/Transforms/Scalar/LICM.cpp
+
41
−
9
View file @
464276f8
...
...
@@ -759,15 +759,24 @@ void LICM::PromoteValuesInLoop() {
}
/// FindPromotableValuesInLoop - Check the current loop for stores to definite
/// pointers, which are not loaded and stored through may aliases
. If these ar
e
/// found, create an alloca for the value, add it
to the PromotedValues list,
/// and keep track of the mapping from value to
alloca.
///
/// pointers, which are not loaded and stored through may aliases
and are saf
e
///
for promotion. If these are
found, create an alloca for the value, add it
///
to the PromotedValues list,
and keep track of the mapping from value to
///
alloca.
void
LICM
::
FindPromotableValuesInLoop
(
std
::
vector
<
std
::
pair
<
AllocaInst
*
,
Value
*>
>
&
PromotedValues
,
std
::
map
<
Value
*
,
AllocaInst
*>
&
ValueToAllocaMap
)
{
Instruction
*
FnStart
=
CurLoop
->
getHeader
()
->
getParent
()
->
begin
()
->
begin
();
SmallVector
<
Instruction
*
,
4
>
LoopExits
;
SmallVector
<
BasicBlock
*
,
4
>
Blocks
;
CurLoop
->
getExitingBlocks
(
Blocks
);
for
(
SmallVector
<
BasicBlock
*
,
4
>::
iterator
BI
=
Blocks
.
begin
(),
BE
=
Blocks
.
end
();
BI
!=
BE
;
++
BI
)
{
BasicBlock
*
BB
=
*
BI
;
LoopExits
.
push_back
(
BB
->
getTerminator
());
}
// Loop over all of the alias sets in the tracker object.
for
(
AliasSetTracker
::
iterator
I
=
CurAST
->
begin
(),
E
=
CurAST
->
end
();
I
!=
E
;
++
I
)
{
...
...
@@ -791,14 +800,37 @@ void LICM::FindPromotableValuesInLoop(
break
;
}
// If GEP base is NULL then the calculated address used by Store or
//
Load instruction is invalid. Do not promote this value because
// it may expose load and store instruction that are covered by
//
condition which may not yet folded.
if
(
GetElementPtrInst
*
GEP
=
dyn_cast
<
GetElementPtrInst
>
(
V
))
if
(
GetElementPtrInst
*
GEP
=
dyn_cast
<
GetElementPtrInst
>
(
V
))
{
//
If GEP base is NULL then the calculated address used by Store or
// Load instruction is invalid. Do not promote this value because
//
it may expose load and store instruction that are covered by
// condition which may not yet folded.
if
(
isa
<
ConstantPointerNull
>
(
GEP
->
getOperand
(
0
)))
PointerOk
=
false
;
// If GEP is use is not dominating loop exit then promoting
// GEP may expose unsafe load and store instructions unconditinally.
if
(
PointerOk
)
for
(
Value
::
use_iterator
UI
=
V
->
use_begin
(),
UE
=
V
->
use_end
();
UI
!=
UE
&&
PointerOk
;
++
UI
)
{
Instruction
*
Use
=
dyn_cast
<
Instruction
>
(
*
UI
);
if
(
!
Use
)
continue
;
for
(
SmallVector
<
Instruction
*
,
4
>::
iterator
ExitI
=
LoopExits
.
begin
(),
ExitE
=
LoopExits
.
end
();
ExitI
!=
ExitE
;
++
ExitI
)
{
Instruction
*
Ex
=
*
ExitI
;
if
(
!
DT
->
dominates
(
Use
,
Ex
)){
PointerOk
=
false
;
break
;
}
}
if
(
!
PointerOk
)
break
;
}
}
if
(
PointerOk
)
{
const
Type
*
Ty
=
cast
<
PointerType
>
(
V
->
getType
())
->
getElementType
();
AllocaInst
*
AI
=
new
AllocaInst
(
Ty
,
0
,
V
->
getName
()
+
".tmp"
,
FnStart
);
...
...
This diff is collapsed.
Click to expand it.
llvm/test/Transforms/LICM/2007-09-17-PromoteValue.ll
+
35
−
0
View file @
464276f8
...
...
@@ -23,4 +23,39 @@ clear_modes.exit: ; preds = %blah.i
unreachable
}
define
i32
@f
(
i8
*
%ptr
)
{
entry:
br
label
%loop.head
loop.head:
; preds = %cond.true, %entry
%x
=
phi
i8
*
[
%ptr
,
%entry
],
[
%ptr.i
,
%cond.true
]
; <i8*> [#uses=1]
%tmp3.i
=
icmp
ne
i8
*
%ptr
,
%x
; <i1> [#uses=1]
br
i1
%tmp3.i
,
label
%cond.true
,
label
%exit
cond.true:
; preds = %loop.head
%ptr.i
=
getelementptr
i8
*
%ptr
,
i32
0
; <i8*> [#uses=2]
store
i8
0
,
i8
*
%ptr.i
br
label
%loop.head
exit:
; preds = %loop.head
ret
i32
0
}
define
i32
@f2
(
i8
*
%p
,
i8
*
%q
)
{
entry:
br
label
%loop.head
loop.head:
; preds = %cond.true, %entry
%tmp3.i
=
icmp
eq
i8
*
null
,
%q
; <i1> [#uses=1]
br
i1
%tmp3.i
,
label
%exit
,
label
%cond.true
cond.true:
; preds = %loop.head
%ptr.i
=
getelementptr
i8
*
%p
,
i32
0
; <i8*> [#uses=2]
store
i8
0
,
i8
*
%ptr.i
br
label
%loop.head
exit:
; preds = %loop.head
ret
i32
0
}
declare
void
@exit
(
i32
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment