aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2018-07-02 20:13:47 +0200
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2018-07-23 13:11:20 +0200
commitc1715a15efc63174218266f400ffb535ee9c5e16 (patch)
tree14527712b5f184e4174b5bdf1d2dcab798af6b2d
parenta4295a5fce926b5b14899194fba402cb3d150b68 (diff)
downloadsparse-dev-c1715a15efc63174218266f400ffb535ee9c5e16.tar.gz
cast: use a switch to handle TRUNC(AND(x,M),N) in simplify_cast()
This is in preparation to handle the other casts: ZEXT & SEXT. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r--simplify.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/simplify.c b/simplify.c
index 94acd567..0982d9d4 100644
--- a/simplify.c
+++ b/simplify.c
@@ -972,8 +972,10 @@ static int simplify_memop(struct instruction *insn)
static int simplify_cast(struct instruction *insn)
{
+ unsigned long long mask;
struct instruction *def;
pseudo_t src;
+ pseudo_t val;
int osize;
int size;
@@ -991,14 +993,16 @@ static int simplify_cast(struct instruction *insn)
def = src->def;
switch (def_opcode(src)) {
case OP_AND:
+ val = def->src2;
+ if (val->type != PSEUDO_VAL)
+ break;
/* A cast of a AND might be a no-op.. */
- if (insn->opcode == OP_TRUNC) {
- pseudo_t val = def->src2;
- if (val->type == PSEUDO_VAL) {
- unsigned long long value = val->value;
- if (!(value >> (size-1)))
- goto simplify;
- }
+ switch (insn->opcode) {
+ case OP_TRUNC:
+ mask = val->value;
+ if (!(mask >> (size-1)))
+ goto simplify;
+ break;
}
break;
case OP_TRUNC: