aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
-rw-r--r--simplify.c9
-rw-r--r--validation/optim/trunc-trunc.c12
2 files changed, 19 insertions, 2 deletions
diff --git a/simplify.c b/simplify.c
index de115d6d..6619bd1b 100644
--- a/simplify.c
+++ b/simplify.c
@@ -1299,8 +1299,13 @@ static int simplify_cast(struct instruction *insn)
}
break;
case OP_TRUNC:
- osize = def->orig_type->bit_size;
- if (insn->opcode == OP_ZEXT && size == osize) {
+ switch (insn->opcode) {
+ case OP_TRUNC:
+ insn->orig_type = def->orig_type;
+ return replace_pseudo(insn, &insn->src1, def->src);
+ case OP_ZEXT:
+ if (size != def->orig_type->bit_size)
+ break;
insn->opcode = OP_AND;
insn->src2 = value_pseudo((1ULL << def->size) - 1);
return replace_pseudo(insn, &insn->src1, def->src);
diff --git a/validation/optim/trunc-trunc.c b/validation/optim/trunc-trunc.c
new file mode 100644
index 00000000..6dc50aee
--- /dev/null
+++ b/validation/optim/trunc-trunc.c
@@ -0,0 +1,12 @@
+char foo(int a)
+{
+ return ((((short) a) + 1) - 1);
+}
+
+/*
+ * check-name: trunc-trunc
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-pattern(1): trunc\\.
+ */