]> granicus.if.org Git - llvm/commit
[InstCombine] Re-commit: Fold 'check for [no] signed truncation' pattern
authorRoman Lebedev <lebedev.ri@gmail.com>
Wed, 18 Jul 2018 10:55:17 +0000 (10:55 +0000)
committerRoman Lebedev <lebedev.ri@gmail.com>
Wed, 18 Jul 2018 10:55:17 +0000 (10:55 +0000)
commit1cd41cb270935f71ca45d7d356bffe77dece8dcc
tree901e9bdfe5c818ca6f3f0cb8534ab61520d17218
parent0c246047310c779463c64a7d864d32b5879559ad
[InstCombine] Re-commit: 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.

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

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.
```

This is a re-commit, as the original patch, committed in rL337190
was reverted in rL337344 as it broke chromium build:
https://bugs.llvm.org/show_bug.cgi?id=38204 and
https://crbug.com/864832
Proofs that the fixed folds are ok: https://rise4fun.com/Alive/VYM

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@337376 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/InstCombine/InstCombineCompares.cpp
test/Transforms/InstCombine/canonicalize-lack-of-signed-truncation-check.ll
test/Transforms/InstCombine/canonicalize-signed-truncation-check.ll