[PATCH] D38037: [InstCombine] Compacting or instructions whose operands are shift instructions
Sanjay Patel via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 27 10:55:05 PDT 2017
spatel added a reviewer: mcrosier.
spatel added a comment.
I haven't looked much at the reassociation pass, but this seems like something that would be simpler to canonicalize there. Did you look at adding a rule there?
Eg, in the "or_or_shift" test, you have a tree of 'or' ops. If you reassociate those so that similar shifts are paired together, instcombine would manage to fold that using existing patterns (although maybe not optimally yet):
define i32 @or_or_shift(i32 %x) local_unnamed_addr #0 {
%1 = and i32 %x, 2
%2 = and i32 %x, 4
%3 = shl nuw nsw i32 %1, 6
%4 = lshr exact i32 %1, 1
%5 = shl nuw nsw i32 %2, 6
%6 = lshr exact i32 %2, 1
%7 = or i32 %3, %5 <--- shl with shl
%8 = or i32 %4, %6 <--- lshr with lshr
%9 = or i32 %7, %8
ret i32 %9
}
$ ./opt -instcombine reass.ll -S
define i32 @or_or_shift(i32 %x) local_unnamed_addr {
%1 = shl i32 %x, 6
%2 = and i32 %1, 384
%3 = lshr i32 %x, 1
%4 = and i32 %3, 3
%5 = or i32 %2, %4
ret i32 %5
}
Repository:
rL LLVM
https://reviews.llvm.org/D38037
More information about the llvm-commits
mailing list