llvm-project/llvm/lib/Transforms/InstCombine
Roman Lebedev b79b4f539b [InstCombine] Fold 'check for [no] signed truncation' pattern
Summary:
[[ https://bugs.llvm.org/show_bug.cgi?id=38149 | PR38149 ]]

As discussed in https://reviews.llvm.org/D49179#1158957 and later,
the IR for 'check for [no] signed truncation' pattern can be improved:
https://rise4fun.com/Alive/gBf
^ that pattern will be produced by Implicit Integer Truncation sanitizer,
https://reviews.llvm.org/D48958 https://bugs.llvm.org/show_bug.cgi?id=21530
in signed case, therefore it is probably a good idea to improve it.

Proofs for this transform: https://rise4fun.com/Alive/mgu
This transform is surprisingly frustrating.
This does not deal with non-splat shift amounts, or with undef shift amounts.
I've outlined what i think the solution should be:
```
  // Potential handling of non-splats: for each element:
  //  * if both are undef, replace with constant 0.
  //    Because (1<<0) is OK and is 1, and ((1<<0)>>1) is also OK and is 0.
  //  * if both are not undef, and are different, bailout.
  //  * else, only one is undef, then pick the non-undef one.
```

The DAGCombine will reverse this transform, see
https://reviews.llvm.org/D49266

Reviewers: spatel, craig.topper

Reviewed By: spatel

Subscribers: JDevlieghere, rkruppe, llvm-commits

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

llvm-svn: 337190
2018-07-16 16:45:42 +00:00
..
CMakeLists.txt InstCombine/AMDGPU: Add dimension-aware image intrinsics to SimplifyDemanded 2018-06-21 13:37:31 +00:00
InstCombineAddSub.cpp [InstCombine] return when SimplifyAssociativeOrCommutative makes a change 2018-07-13 01:18:07 +00:00
InstCombineAndOrXor.cpp [InstCombine] return when SimplifyAssociativeOrCommutative makes a change 2018-07-13 01:18:07 +00:00
InstCombineCalls.cpp Simplify recursive launder.invariant.group and strip 2018-07-12 23:55:20 +00:00
InstCombineCasts.cpp [Local] replaceAllDbgUsesWith: Update debug values before RAUW 2018-07-06 17:32:39 +00:00
InstCombineCompares.cpp [InstCombine] Fold 'check for [no] signed truncation' pattern 2018-07-16 16:45:42 +00:00
InstCombineInternal.h [InstCombine] allow more shuffle folds using safe constants 2018-07-09 23:22:47 +00:00
InstCombineLoadStoreAlloca.cpp llvm: Add support for "-fno-delete-null-pointer-checks" 2018-07-09 22:27:23 +00:00
InstCombineMulDivRem.cpp [InstCombine] Corrections in comments for division transformation (NFC) 2018-07-15 17:06:59 +00:00
InstCombinePHI.cpp Move Analysis/Utils/Local.h back to Transforms 2018-06-04 21:23:21 +00:00
InstCombineSelect.cpp [InstCombine] add more SPFofSPF folding 2018-07-16 02:23:00 +00:00
InstCombineShifts.cpp [InstCombine] simplify binops before trying other folds 2018-06-21 17:06:36 +00:00
InstCombineSimplifyDemanded.cpp [X86] Remove and autoupgrade the scalar fma intrinsics with masking. 2018-07-12 00:29:56 +00:00
InstCombineTables.td InstCombine/AMDGPU: Add dimension-aware image intrinsics to SimplifyDemanded 2018-06-21 13:37:31 +00:00
InstCombineVectorOps.cpp [InstCombine] allow flag propagation when using safe constant 2018-07-10 16:09:49 +00:00
InstructionCombining.cpp [InstCombine] allow more shuffle folds using safe constants 2018-07-09 23:22:47 +00:00
LLVMBuild.txt