llvm-project/llvm/test
Chuang-Yu Cheng dbe00d51b4 SimplifyCFG is able to detect the pattern:
(i == 5334 || i == 5335)
to:
    ((i & -2) == 5334)

This transformation has some incorrect side conditions. Specifically, the
transformation is only applied when the right-hand side constant (5334 in
the example) is a power of two not equal and not equal to the negated mask.
These side conditions were added in r258904 to fix PR26323. The correct side
condition is that: ((Constant & Mask) == Constant)[(5334 & -2) == 5334].

It's a little bit hard to see why these transformations are correct and what
the side conditions ought to be. Here is a CVC3 program to verify them for
64-bit values:
    ONE  : BITVECTOR(64) = BVZEROEXTEND(0bin1, 63);
    x    : BITVECTOR(64);
    y    : BITVECTOR(64);
    z    : BITVECTOR(64);
    mask : BITVECTOR(64) = BVSHL(ONE, z);
    QUERY( (y & ~mask = y) =>
           ((x & ~mask = y) <=> (x = y OR x = (y |  mask)))
    );

Please note that each pattern must be a dual implication (<--> or iff). One
directional implication can create spurious matches. If the implication is
only one-way, an unsatisfiable condition on the left side can imply a
satisfiable condition on the right side. Dual implication ensures that
satisfiable conditions are transformed to other satisfiable conditions and
unsatisfiable conditions are transformed to other unsatisfiable conditions.

Here is a concrete example of a unsatisfiable condition on the left
implying a satisfiable condition on the right:
    mask = (1 << z)
    (x & ~mask) == y --> (x == y || x == (y | mask))

Substituting y = 3, z = 0 yields:
    (x & -2) == 3 --> (x == 3 || x == 2)

The version of this code before r258904 had no side-conditions and
incorrectly justified itself in comments through one-directional
implication.

Thanks to Chandler for the suggestion!

Author: Thomas Jablin (tjablin)
Reviewers: chandlerc majnemer hfinkel cycheng

http://reviews.llvm.org/D21417

llvm-svn: 272873
2016-06-16 04:44:25 +00:00
..
Analysis [CFLAA] Tag arguments as escaped instead of unknown. 2016-06-14 18:12:28 +00:00
Assembler IR: Introduce local_unnamed_addr attribute. 2016-06-14 21:01:22 +00:00
Bindings Add support for callsite in the new C API for attributes 2016-06-15 05:14:29 +00:00
Bitcode IR: Introduce local_unnamed_addr attribute. 2016-06-14 21:01:22 +00:00
BugPoint
CodeGen AArch64: allow MOV (imm) alias to be printed 2016-06-16 01:42:25 +00:00
DebugInfo AArch64: allow MOV (imm) alias to be printed 2016-06-16 01:42:25 +00:00
Examples
ExecutionEngine [MIPS][LLVM-MC] Fix Disassemble of Negative Offset 2016-05-24 09:57:10 +00:00
Feature IR: Introduce local_unnamed_addr attribute. 2016-06-14 21:01:22 +00:00
FileCheck [FileCheck] Add --check-prefixes as a shorthand for multiple --check-prefix options. 2016-06-14 14:28:04 +00:00
Instrumentation [esan|cfrag] Handle complex GEP instr in the cfrag tool 2016-06-10 22:28:55 +00:00
Integer Make "@name =" mandatory for globals in .ll files. 2016-05-10 18:22:45 +00:00
JitListener
LTO IR: Introduce local_unnamed_addr attribute. 2016-06-14 21:01:22 +00:00
LibDriver
Linker ValueMapper: fix assertion when null-mapping a constant for linking metadata 2016-05-28 17:26:03 +00:00
MC AArch64: allow MOV (imm) alias to be printed 2016-06-16 01:42:25 +00:00
Object [mips] Remove CPU-only triples from llvm-objdump commands. 2016-06-03 10:22:22 +00:00
ObjectYAML [yaml2obj] Sort MachO LinkEdit write operations based on offset 2016-06-03 16:58:05 +00:00
Other Statistic: Add machine parseable json output 2016-06-15 20:19:16 +00:00
SymbolRewriter
TableGen [Target] Introduce a generic opcode for bitwise OR: G_OR. 2016-06-08 16:12:19 +00:00
ThinLTO/X86 [ThinLTO] Resolve LinkOnceAny 2016-05-26 14:16:52 +00:00
Transforms SimplifyCFG is able to detect the pattern: 2016-06-16 04:44:25 +00:00
Unit
Verifier Verifier: check that functions have at most a single !prof attachment. 2016-06-14 23:13:15 +00:00
YAMLParser
tools Fix llvm-objdump when disassembling a stripped Mach-O binary with the -macho option. 2016-06-15 21:14:01 +00:00
.clang-format
CMakeLists.txt [cmake] Fix builds with LLVM_ENABLE_PIC=0 2016-06-02 16:29:07 +00:00
TestRunner.sh
lit.cfg test: Be consistent with clang's sanitizer lit config 2016-05-23 23:02:11 +00:00
lit.site.cfg.in Add the printing the Mach-O (__LLVM,__bundle) xar archive file section "verbosely" 2016-05-23 21:34:12 +00:00