Commit 2576b281 authored by Matthias Braun's avatar Matthias Braun
Browse files

amd64: enumerate commutative binops in spec file, add missing xXorp to list

parent d582c836
...@@ -37,12 +37,16 @@ static unsigned get_first_same(arch_register_req_t const *const req) ...@@ -37,12 +37,16 @@ static unsigned get_first_same(arch_register_req_t const *const req)
panic("same position not found"); panic("same position not found");
} }
static bool is_commutative(const ir_node *node)
{
return arch_get_irn_flags(node) & amd64_arch_irn_flag_commutative_binop;
}
static bool try_swap_inputs(ir_node *node) static bool try_swap_inputs(ir_node *node)
{ {
/* commutative operation, just switch the inputs */ /* commutative operation, just switch the inputs */
if (is_amd64_Add(node) || is_amd64_And(node) || is_amd64_Or(node) if (is_commutative(node)) {
|| is_amd64_Xor(node) || is_amd64_IMul(node) || is_amd64_xAdds(node) assert(get_amd64_attr_const(node)->op_mode == AMD64_OP_REG_REG);
|| is_amd64_xMuls(node)) {
/* TODO: support Cmp input swapping */ /* TODO: support Cmp input swapping */
ir_node *in0 = get_irn_n(node, 0); ir_node *in0 = get_irn_n(node, 0);
ir_node *in1 = get_irn_n(node, 1); ir_node *in1 = get_irn_n(node, 1);
......
...@@ -16,6 +16,10 @@ ...@@ -16,6 +16,10 @@
#include "compiler.h" #include "compiler.h"
#include "../ia32/x86_cc.h" #include "../ia32/x86_cc.h"
enum amd64_arch_irn_flags_t {
amd64_arch_irn_flag_commutative_binop = arch_irn_flag_backend << 0,
};
typedef enum { typedef enum {
INSN_MODE_64, INSN_MODE_64,
INSN_MODE_32, INSN_MODE_32,
......
...@@ -56,6 +56,10 @@ sub amd64_custom_init_attr { ...@@ -56,6 +56,10 @@ sub amd64_custom_init_attr {
} }
$custom_init_attr_func = \&amd64_custom_init_attr; $custom_init_attr_func = \&amd64_custom_init_attr;
%custom_irn_flags = (
commutative => "(arch_irn_flags_t)amd64_arch_irn_flag_commutative_binop",
);
$default_copy_attr = "amd64_copy_attr"; $default_copy_attr = "amd64_copy_attr";
%init_attr = ( %init_attr = (
...@@ -139,7 +143,7 @@ Leave => { ...@@ -139,7 +143,7 @@ Leave => {
}, },
Add => { Add => {
irn_flags => [ "rematerializable" ], irn_flags => [ "rematerializable", "commutative" ],
state => "exc_pinned", state => "exc_pinned",
reg_req => { out => [ "gp", "flags", "none" ] }, reg_req => { out => [ "gp", "flags", "none" ] },
arity => "variable", arity => "variable",
...@@ -151,7 +155,7 @@ Add => { ...@@ -151,7 +155,7 @@ Add => {
}, },
And => { And => {
irn_flags => [ "rematerializable" ], irn_flags => [ "rematerializable", "commutative" ],
state => "exc_pinned", state => "exc_pinned",
reg_req => { out => [ "gp", "flags", "none" ] }, reg_req => { out => [ "gp", "flags", "none" ] },
arity => "variable", arity => "variable",
...@@ -190,7 +194,7 @@ IDiv => { ...@@ -190,7 +194,7 @@ IDiv => {
}, },
IMul => { IMul => {
irn_flags => [ "rematerializable" ], irn_flags => [ "rematerializable", "commutative" ],
state => "exc_pinned", state => "exc_pinned",
reg_req => { out => [ "gp", "flags", "none" ] }, reg_req => { out => [ "gp", "flags", "none" ] },
outs => [ "res", "flags", "M" ], outs => [ "res", "flags", "M" ],
...@@ -203,6 +207,8 @@ IMul => { ...@@ -203,6 +207,8 @@ IMul => {
IMul1Op => { IMul1Op => {
# Do not rematerialize this node # Do not rematerialize this node
# TODO: should mark this commutative as soon as the backend code
# can handle this special case
# It produces 2 results and has strict constraints # It produces 2 results and has strict constraints
state => "exc_pinned", state => "exc_pinned",
reg_req => { out => [ "rax", "flags", "none", "rdx" ] }, reg_req => { out => [ "rax", "flags", "none", "rdx" ] },
...@@ -228,7 +234,7 @@ Mul => { ...@@ -228,7 +234,7 @@ Mul => {
}, },
Or => { Or => {
irn_flags => [ "rematerializable" ], irn_flags => [ "rematerializable", "commutative" ],
state => "exc_pinned", state => "exc_pinned",
reg_req => { out => [ "gp", "flags", "none" ] }, reg_req => { out => [ "gp", "flags", "none" ] },
outs => [ "res", "flags", "M" ], outs => [ "res", "flags", "M" ],
...@@ -323,7 +329,7 @@ Not => { ...@@ -323,7 +329,7 @@ Not => {
}, },
Xor => { Xor => {
irn_flags => [ "rematerializable" ], irn_flags => [ "rematerializable", "commutative" ],
state => "exc_pinned", state => "exc_pinned",
reg_req => { out => [ "gp", "flags", "none" ] }, reg_req => { out => [ "gp", "flags", "none" ] },
arity => "variable", arity => "variable",
...@@ -482,7 +488,7 @@ Return => { ...@@ -482,7 +488,7 @@ Return => {
# SSE # SSE
xAdds => { xAdds => {
irn_flags => [ "rematerializable" ], irn_flags => [ "rematerializable", "commutative" ],
state => "exc_pinned", state => "exc_pinned",
reg_req => { out => [ "xmm", "none", "none" ] }, reg_req => { out => [ "xmm", "none", "none" ] },
outs => [ "res", "none", "M" ], outs => [ "res", "none", "M" ],
...@@ -514,7 +520,7 @@ xMovs => { ...@@ -514,7 +520,7 @@ xMovs => {
}, },
xMuls => { xMuls => {
irn_flags => [ "rematerializable" ], irn_flags => [ "rematerializable", "commutative" ],
state => "exc_pinned", state => "exc_pinned",
reg_req => { out => [ "xmm", "none", "none" ] }, reg_req => { out => [ "xmm", "none", "none" ] },
outs => [ "res", "none", "M" ], outs => [ "res", "none", "M" ],
...@@ -571,7 +577,7 @@ xXorp0 => { ...@@ -571,7 +577,7 @@ xXorp0 => {
}, },
xXorp => { xXorp => {
irn_flags => [ "rematerializable" ], irn_flags => [ "rematerializable", "commutative" ],
state => "exc_pinned", state => "exc_pinned",
reg_req => { out => [ "xmm", "none", "none" ] }, reg_req => { out => [ "xmm", "none", "none" ] },
arity => "variable", arity => "variable",
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment