Skip to content

Commit

Permalink
Merge branches 'fix-can-move-to' and 'asr-synth' into next
Browse files Browse the repository at this point in the history
  • Loading branch information
lucvoo committed Jan 24, 2021
2 parents 879b11d + 36df56f commit 0fb77bb
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
13 changes: 12 additions & 1 deletion simplify.c
Original file line number Diff line number Diff line change
Expand Up @@ -2068,7 +2068,7 @@ static int simplify_memop(struct instruction *insn)
static int simplify_cast(struct instruction *insn)
{
unsigned long long mask;
struct instruction *def;
struct instruction *def, *def2;
pseudo_t src = insn->src;
pseudo_t val;
int osize;
Expand Down Expand Up @@ -2165,6 +2165,17 @@ static int simplify_cast(struct instruction *insn)
case OP_TRUNC:
insn->orig_type = def->orig_type;
return replace_pseudo(insn, &insn->src1, def->src);
case OP_SEXT:
if (size != def->orig_type->bit_size)
break;
if (DEF_OPCODE(def2, def->src) != OP_LSR)
break;
if (def2->src2 != value_pseudo(size - def->size))
break;
// SEXT(TRUNC(LSR(x, N))) --> ASR(x, N)
insn->opcode = OP_ASR;
insn->src2 = def2->src2;
return replace_pseudo(insn, &insn->src1, def2->src1);
case OP_ZEXT:
if (size != def->orig_type->bit_size)
break;
Expand Down
27 changes: 27 additions & 0 deletions validation/optim/lsr-to-asr.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
int lsr_to_asr24(int x)
{
return ((signed char)(((unsigned)x) >> 24)) == (x >> 24);
}


struct s {
int :30;
signed int f:2;
};

int lsr_to_asr30(int a)
{
union {
int i;
struct s s;
} u = { .i = a };
return u.s.f == (a >> 30);
}

/*
* check-name: lsr-to-asr
* check-command: test-linearize -Wno-decl $file
*
* check-output-ignore
* check-output-returns: 1
*/

0 comments on commit 0fb77bb

Please sign in to comment.