If the effective mask (C & M) is different than the outer mask C, then this later 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 755371002..5a802d207 100644 --- a/simplify.c +++ b/simplify.c @@ -622,6 +622,10 @@ static int simplify_mask_or(struct instruction *insn, unsigned long long mask, s // if (C & M) == M: OR(x, C) -> (C & M) return replace_pseudo(insn, &insn->src1, value_pseudo(nval)); } + 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