Added tests for unary integer instructions

This commit is contained in:
Dmitry Stogov 2022-04-08 16:40:28 +03:00
parent fa7a34c629
commit f1cc9a4ddb
6 changed files with 165 additions and 5 deletions

View File

@ -79,4 +79,6 @@ clean:
minilua ir_$(DASM_ARCH).c \
ir_fold_hash.h gen_ir_fold_hash \
ir.dot ir.pdf 2.log \
b perf.data perf.data.old perf.data.jitted
b perf.data perf.data.old perf.data.jitted \
tests/*.diff tests/*.out tests/*.exp tests/*.ir \
tests/x86_64/*.diff tests/x86_64/*.out tests/x86_64/*.exp tests/x86_64/*.ir

93
TODO Normal file
View File

@ -0,0 +1,93 @@
- type casting nodes
- overflow detection nodes
- va_arg nodes
- BSTART, BEND nodes (to free data allocated by ALLOCA)
- ENTRY node for multy-entry units
- IJMP
- guards
- variable name binding
- VLOAD, VSTORE -> SSA
? reassociation folding rules
- folding engine improvement (one rule for few patterns)
- irreducable loops detection
- irreducable loops support
- range inference and PI node
- SCCP edge cases
- Folding after SCCP
- local scheduling according to data dependencies, register presure and pipeline stalls
- basic block trace scheduling
? C code generation
- VLOAD, VSTORE
? instruction selection
- xor, btsl=INCL, btrl=EXCL, btl=IN, bsr, maxss, maxsd, minss, minsd
- MOVZX to avoid a SHIFT and AND instruction
- Using CMOVcc to remove branches
- mov rax, 123456789abcdef0h ; 10 bytes (64-bit constant)
- mov rax, -100 ; 7 bytes (32-bit sign-extended)
- mov eax, 100 ; 5 bytes (32-bit zero-extended)
? register allocation
+ linear scan
- separate INT and FP allocation phases
+ use positions
? fixed registers constraints
+ fixed input
+ fixed output
+ fixed tmp
+ fixed intervals for parameters
- accurate fixed interval construction
- constraints
- kill
- restricted regset
- temporary registers
? spills
+ spill slot allocation ( uniqe for each VREG)
- uniqe for each VREG
- SpillRange ???
- splitting
- SplitAt
- splinting
- spill only at cold path if possible
? hints
+ hints for fixed input/outpu registers
+ hints for parameter nodes
- hints for call arguments
- hints propagation
- hints and low priority
? code generation
- POW, NEG (fp), ABS, OVERFLOW, MIN, MAX, COND, TAILCALL, ALLOCA, VLOAD, VSTORE, LOAD, STORE
- SWITCH
- ir_last_use
- 64-bit constant (ir_emit_ref, ir_emit_dssa_move)
- binop_int $imm, mem
- commutative insns and swap (binop_int, mul, binop_sse, binop_avx, cmp_int, cmp_fp, cmp_br_int)
- dessa_move (push, pop)
- param_move
- temporary register (e.g. for unsupported immediate operand in mul, div)
- temporary register for swap (dessa3.ir)
- temporary register for spill loads and stores
- parallel parameter loading
- parallel argument passing
- return merge/split
? binary code emission
+ DynAsm
- BinAsm
? disassembler
- .rodata section and relative data labels
- modules (functions, data objecs, import, export, prototypes, forward declarations, memory segments, ref data, expr data)
- C compiler
- interpreter
- alias analyzes
- PHP support

View File

@ -1071,19 +1071,26 @@ static uint32_t ir_match_insn(ir_ctx *ctx, ir_ref ref, ir_block *bb)
// case IR_SUB_OV:
// case IR_MUL_OV:
// case IR_OVERFLOW:
case IR_BSWAP:
case IR_NOT:
return IR_OP_INT;
case IR_NEG:
if (IR_IS_TYPE_INT(insn->type)) {
return IR_OP_INT;
} else {
IR_ASSERT(0); return IR_SKIP; // xorps
IR_ASSERT(0); return IR_SKIP; // xorpd .LC0(%rip), %xmm0; 0 0x80000000 0 0
// vxorpd .LC0(%rip), %xmm0, %xmm0
// xorps .LC0(%rip), %xmm0; 0x80000000 0 0 0
// vxorps .LC0(%rip), %xmm0, %xmm0
}
case IR_ABS:
if (IR_IS_TYPE_INT(insn->type)) {
IR_ASSERT(0); return IR_SKIP; // TODO: ???
IR_ASSERT(0); return IR_SKIP; // movl %edi, %eax; negl %eax; cmovs %edi, %eax
} else {
IR_ASSERT(0); return IR_SKIP; // andps
IR_ASSERT(0); return IR_SKIP; // andpd .LC0(%rip), %xmm0; 0xffffffff 0x7fffffff 0 0
// vandpd .LC0(%rip), %xmm0, %xmm0
// andps .LC0(%rip), %xmm0; 0x7fffffff 0 0 0
// vandps .LC0(%rip), %xmm0, %xmm0
}
case IR_OR:
if (IR_IS_CONST_REF(insn->op2)) {
@ -1164,7 +1171,6 @@ static uint32_t ir_match_insn(ir_ctx *ctx, ir_ref ref, ir_block *bb)
return IR_SHIFT_CONST;
}
return IR_SHIFT;
// case IR_BSWAP:
// case IR_MIN:
// case IR_MAX:
// case IR_COND:
@ -1743,6 +1749,17 @@ void ir_emit_op_int(ir_ctx *ctx, ir_ref def, ir_insn *insn)
| ASM_REG_OP not, insn->type, reg
} else if (insn->op == IR_NEG) {
| ASM_REG_OP neg, insn->type, reg
} else if (insn->op == IR_BSWAP) {
switch (ir_type_size[insn->type]) {
case 4:
| bswap Rd(reg)
break;
case 8:
| bswap Rq(reg)
break;
default:
IR_ASSERT(0);
}
} else {
IR_ASSERT(0);
}

View File

@ -0,0 +1,16 @@
--TEST--
001: bswap function
--ARGS--
-S
--CODE--
{
l_1 = START(l_4);
int32_t x = PARAM(l_1, "x", 1);
int32_t ret = BSWAP(x);
l_4 = RETURN(l_1, ret);
}
--EXPECT--
test:
movl %edi, %eax
bswapl %eax
retq

16
tests/x86_64/neg_001.irt Normal file
View File

@ -0,0 +1,16 @@
--TEST--
001: neg function
--ARGS--
-S
--CODE--
{
l_1 = START(l_4);
int32_t x = PARAM(l_1, "x", 1);
int32_t ret = NEG(x);
l_4 = RETURN(l_1, ret);
}
--EXPECT--
test:
movl %edi, %eax
negl %eax
retq

16
tests/x86_64/not_001.irt Normal file
View File

@ -0,0 +1,16 @@
--TEST--
001: nit function
--ARGS--
-S
--CODE--
{
l_1 = START(l_4);
int32_t x = PARAM(l_1, "x", 1);
int32_t ret = NOT(x);
l_4 = RETURN(l_1, ret);
}
--EXPECT--
test:
movl %edi, %eax
notl %eax
retq