OSDN Git Service

[InstCombine] Shift amount reassociation (PR42391)
authorRoman Lebedev <lebedev.ri@gmail.com>
Sat, 29 Jun 2019 11:51:50 +0000 (11:51 +0000)
committerRoman Lebedev <lebedev.ri@gmail.com>
Sat, 29 Jun 2019 11:51:50 +0000 (11:51 +0000)
commit40b63d7e1236d349b818c7435f74b4551aacc146
tree2fbcc459857a908714488b7408143377b482375b
parente30b1c0c22a69971612e014f958ab33916c99f48
[InstCombine] Shift amount reassociation (PR42391)

Summary:
Given pattern:
`(x shiftopcode Q) shiftopcode K`
we should rewrite it as
`x shiftopcode (Q+K)`  iff `(Q+K) u< bitwidth(x)`
This is valid for any shift, but they must be identical.

* https://rise4fun.com/Alive/9E2
* exact on both lshr => exact https://rise4fun.com/Alive/plHk
* exact on both ashr => exact https://rise4fun.com/Alive/QDAA
* nuw on both shl => nuw https://rise4fun.com/Alive/5Uk
* nsw on both shl => nsw https://rise4fun.com/Alive/0plg

Should fix [[ https://bugs.llvm.org/show_bug.cgi?id=42391 | PR42391]].

Reviewers: spatel, nikic, RKSimon

Reviewed By: nikic

Subscribers: llvm-commits

Tags: #llvm

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@364712 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/InstCombine/InstCombineShifts.cpp
test/Transforms/InstCombine/shift-amount-reassociation.ll