If the effective mask (M) corresponding to OP(_, K) is different than the combined mask (C & M), then the inner mask (C) can be replaced by the smaller (C & M), giving: OP((x | M'), K) with M' == (C & M). For example, code like: int foo(int x) { return (x | 0xfffffff0) & 0xfff; } is now simplified into: foo: or.32 %r2 <- %arg1, $0xff0 and.32 %r3 <- %r2, $0xfff ret.32 %r3 while previously, the constant was not reduced: foo: or.32 %r2 <- %arg1, $0xfffffff0 and.32 %r3 <- %r2, $0xfff ret.32 %r3 Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx> --- simplify.c | 4 ++++ validation/optim/and-or-constant2.c | 1 - 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/simplify.c b/simplify.c index a36083789..fce99551a 100644 --- a/simplify.c +++ b/simplify.c @@ -626,6 +626,10 @@ static int simplify_mask_or(struct instruction *insn, unsigned long long mask, s // if (C & M) == M: OR(x, C) -> M return replace_pseudo(insn, &insn->src1, value_pseudo(mask)); } + if (nval != oval && !multi_users(or->target)) { + // if (C & M) != C: OR(x, C) -> OR(x, (C & M)) + return replace_pseudo(or, &or->src2, value_pseudo(nval)); + } } return 0; } diff --git a/validation/optim/and-or-constant2.c b/validation/optim/and-or-constant2.c index 82e0d3c69..d7e66f9c0 100644 --- a/validation/optim/and-or-constant2.c +++ b/validation/optim/and-or-constant2.c @@ -6,7 +6,6 @@ int foo(int x) /* * check-name: and-or-constant2 * check-command: test-linearize -Wno-decl $file - * check-known-to-fail * * check-output-ignore * check-output-contains: or\\..*\\$0xff0 -- 2.18.0