Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
OneLastCompiler
compiler
Commits
be3abd3e
Commit
be3abd3e
authored
8 months ago
by
seven-mile
Browse files
Options
Download
Patches
Plain Diff
fix: should return rhs
parent
b03f5e5f
main
canonicalize
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/olc/ir/IR.h
+7
-0
include/olc/ir/IR.h
include/olc/passes/CanonicalizePass.h
+3
-7
include/olc/passes/CanonicalizePass.h
with
10 additions
and
7 deletions
+10
-7
include/olc/ir/IR.h
+
7
−
0
View file @
be3abd3e
...
@@ -462,6 +462,13 @@ struct ConstantValue : Constant {
...
@@ -462,6 +462,13 @@ struct ConstantValue : Constant {
int
getInt
()
const
{
return
std
::
get
<
int
>
(
value
);
}
int
getInt
()
const
{
return
std
::
get
<
int
>
(
value
);
}
float
getFloat
()
const
{
return
std
::
get
<
float
>
(
value
);
}
float
getFloat
()
const
{
return
std
::
get
<
float
>
(
value
);
}
bool
isZero
()
const
{
if
(
isInt
())
return
getInt
()
==
0
;
else
return
getFloat
()
==
0
.
0
;
}
void
print
(
std
::
ostream
&
os
)
const
override
{
void
print
(
std
::
ostream
&
os
)
const
override
{
getType
()
->
print
(
os
);
getType
()
->
print
(
os
);
if
(
isInt
())
if
(
isInt
())
...
...
This diff is collapsed.
Click to expand it.
include/olc/passes/CanonicalizePass.h
+
3
−
7
View file @
be3abd3e
...
@@ -19,7 +19,7 @@ public:
...
@@ -19,7 +19,7 @@ public:
auto
*
lhs
=
inst
->
getLHS
(),
*
rhs
=
inst
->
getRHS
();
auto
*
lhs
=
inst
->
getLHS
(),
*
rhs
=
inst
->
getRHS
();
bool
lhsConst
=
isa
<
ConstantValue
>
(
lhs
),
rhsConst
=
isa
<
ConstantValue
>
(
rhs
);
bool
lhsConst
=
isa
<
ConstantValue
>
(
lhs
),
rhsConst
=
isa
<
ConstantValue
>
(
rhs
);
// assert((!lhsConst || !rhsConst) && "should run constfold first");
// assert((!lhsConst || !rhsConst) && "should run constfold first");
if
(
lhsConst
)
{
if
(
lhsConst
&&
!
rhsConst
)
{
if
(
inst
->
isCommutable
())
{
if
(
inst
->
isCommutable
())
{
std
::
swap
(
lhs
,
rhs
);
std
::
swap
(
lhs
,
rhs
);
std
::
swap
(
lhsConst
,
rhsConst
);
std
::
swap
(
lhsConst
,
rhsConst
);
...
@@ -44,13 +44,9 @@ public:
...
@@ -44,13 +44,9 @@ public:
}
}
}
}
if
(
tag
==
Value
::
Tag
::
Sub
&&
rhsConst
)
{
rhs
=
cast
<
ConstantValue
>
(
rhs
)
->
map
([](
auto
&&
arg
)
{
return
-
arg
;
});
}
if
((
tag
==
Value
::
Tag
::
Add
||
tag
==
Value
::
Tag
::
Sub
)
&&
rhsConst
&&
if
((
tag
==
Value
::
Tag
::
Add
||
tag
==
Value
::
Tag
::
Sub
)
&&
rhsConst
&&
cast
<
ConstantValue
>
(
rhs
)
->
getInt
()
==
0
)
{
cast
<
ConstantValue
>
(
rhs
)
->
isZero
()
)
{
return
r
hs
;
return
l
hs
;
}
}
inst
->
tag
=
tag
;
inst
->
tag
=
tag
;
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
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
Menu
Explore
Projects
Groups
Topics
Snippets