hanchenye-llvm-project/llvm/test/Transforms/InstSimplify
Roman Lebedev b060ce45ca [InstSimplify] add nuw %x, -1 -> -1 fold.
Summary:
`%ret = add nuw i8 %x, C`
From [[ https://llvm.org/docs/LangRef.html#add-instruction | langref ]]:
    nuw and nsw stand for “No Unsigned Wrap” and “No Signed Wrap”,
    respectively. If the nuw and/or nsw keywords are present,
    the result value of the add is a poison value if unsigned
    and/or signed overflow, respectively, occurs.

So if `C` is `-1`, `%x` can only be `0`, and the result is always `-1`.

I'm not sure we want to use `KnownBits`/`LVI` here, because there is
exactly one possible value (all bits set, `-1`), so some other pass
should take care of replacing the known-all-ones with constant `-1`.

The `test/Transforms/InstCombine/set-lowbits-mask-canonicalize.ll` change *is* confusing.
What happening is, before this: (omitting `nuw` for simplicity)
1. First, InstCombine D47428/rL334127 folds `shl i32 1, %NBits`) to `shl nuw i32 -1, %NBits`
2. Then, InstSimplify D47883/rL334222 folds `shl nuw i32 -1, %NBits` to `-1`,
3. `-1` is inverted to `0`.
But now:
1. *This* InstSimplify fold `%ret = add nuw i32 %setbit, -1` -> `-1` happens first,
   before InstCombine D47428/rL334127 fold could happen.
Thus we now end up with the opposite constant,
and it is all good: https://rise4fun.com/Alive/OA9

https://rise4fun.com/Alive/sldC
Was mentioned in D47428 review.
Follow-up for D47883.

Reviewers: spatel, craig.topper

Reviewed By: spatel

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D47908

llvm-svn: 334298
2018-06-08 15:44:47 +00:00
..
2010-12-20-Boolean.ll
2011-01-14-Thread.ll
2011-02-01-Vector.ll
2011-09-05-InsertExtractValue.ll
2011-10-27-BinOpCrash.ll
2011-11-23-MaskedBitsCrash.ll
2013-04-19-ConstantFoldingCrash.ll
AndOrXor.ll [PatternMatch] allow undef elements when matching a vector zero 2018-04-22 17:07:44 +00:00
add-mask.ll
addsub.ll
and-icmps-same-ops.ll
and-or-icmp-zero.ll
assume.ll [DebugInfo] Add DILabel metadata and intrinsic llvm.dbg.label. 2018-05-09 02:40:45 +00:00
bitcast-vector-fold.ll
bitreverse-fold.ll
bitreverse.ll
bswap.ll
call.ll
cast-unsigned-icmp-cmp-0.ll [PatternMatch] allow undef elements when matching a vector zero 2018-04-22 17:07:44 +00:00
cast.ll
compare.ll
constantfold-add-nuw-allones-to-allones.ll [InstSimplify] add nuw %x, -1 -> -1 fold. 2018-06-08 15:44:47 +00:00
constantfold-shl-nuw-C-to-C.ll [NFC][InstSimplify] One more negative test for shl nuw C, %x -> C fold. 2018-06-07 21:19:45 +00:00
dead-code-removal.ll
div.ll [PatternMatch] allow undef elements when matching a vector zero 2018-04-22 17:07:44 +00:00
exact-nsw-nuw.ll
extract-element.ll
fast-math.ll [PatternMatch] allow undef elements when matching vector FP +0.0 2018-03-25 21:16:33 +00:00
fdiv.ll [InstSimplify] add tests for FP with undef operand; NFC 2018-02-27 20:17:18 +00:00
floating-point-arithmetic.ll [PatternMatch] allow undef elements when matching vector FP +0.0 2018-03-25 21:16:33 +00:00
floating-point-compare.ll [PatternMatch] enhance m_NaN() to ignore undef elements in vectors 2018-03-12 22:18:47 +00:00
fold-builtin-fma.ll
fold-intrinsics.ll
fp-nan.ll [InstSimplify] fp_binop X, NaN --> NaN 2018-03-21 19:31:53 +00:00
fp-undef.ll [InstSimplify] fp_binop X, undef --> NaN 2018-03-10 16:51:28 +00:00
gep.ll [InstSimplify] regenerate checks, move tests; NFC 2018-03-23 15:31:31 +00:00
icmp-bool-constant.ll [PatternMatch] enhance m_One() to ignore undef elements in vectors 2018-02-17 16:00:42 +00:00
icmp-constant.ll
icmp-ranges.ll
implies.ll
insertelement.ll
load-relative-32.ll
load-relative.ll
load.ll
log-exp-intrinsic.ll [InstSimplify] allow exp/log simplifications with only 'reassoc' FMF 2018-02-12 23:51:23 +00:00
logic-of-fcmps.ll
maxmin.ll
mul.ll [PatternMatch] allow undef elements when matching a vector zero 2018-04-22 17:07:44 +00:00
negate.ll [PatternMatch] allow undef elements when matching a vector zero 2018-04-22 17:07:44 +00:00
noalias-ptr.ll
or-icmps-same-ops.ll
or.ll [PatternMatch, InstSimplify] enhance m_AllOnes() to ignore undef elements in vectors 2018-02-18 18:05:08 +00:00
past-the-end.ll
phi.ll
pr28725.ll
pr33957.ll
ptr_diff.ll
reassociate.ll
rem.ll [PatternMatch] allow undef elements when matching a vector zero 2018-04-22 17:07:44 +00:00
require-dominator.ll
returned.ll
select.ll Reland r301880(!): "[InstSimplify] Handle selects of GEPs with 0 offset" 2018-04-24 00:25:01 +00:00
shift-128-kb.ll
shift-knownbits.ll
shift.ll [PatternMatch] allow undef elements when matching a vector zero 2018-04-22 17:07:44 +00:00
shr-nop.ll [InstSimplify] move tests for shifts; NFC 2018-04-21 16:58:00 +00:00
shufflevector.ll
signed-div-rem.ll
simplify-nested-bitcast.ll
undef.ll
vec-cmp.ll
vector_gep.ll [ConstantFolding, InstSimplify] Handle more vector GEPs 2018-03-15 16:00:29 +00:00
vector_ptr_bitcast.ll