[PATCH] Teach instcombine how to combine multiply of constant splat of known power-of-2
Rafael EspĂndola
rafael.espindola at gmail.com
Wed May 29 12:18:46 PDT 2013
On 29 May 2013 07:05, <Andrea_DiBiagio at sn.scee.net> wrote:
> Hi,
>
> Here is an updated patch that deals with the general case where a multiply
> by a vector of constants known
> power-of-2 are combined into shifts.
> My original patch only allowed combining multiply by splat of known
> constant powers of 2.
The testcases take and return scalars that are bitcast to and from a
vector. For example, you have:
define i32 @AddToSelf_i8(i32 %InVec) {
entry:
%0 = bitcast i32 %InVec to <4 x i8>
%mul = mul <4 x i8> %0, <i8 2, i8 2, i8 2, i8 2>
%1 = bitcast <4 x i8> %mul to i32
ret i32 %1
}
Why not the simpler:
define <4 x i8> @AddToSelf_i8(<4 x i8> %InVec) {
entry:
%mul = mul <4 x i8> %InVec, <i8 2, i8 2, i8 2, i8 2>
ret <4 x i8> %mul
}
A really small nit is that you don't need the "-o -" in the command
line, opt will print to stdout when reading from stdin.
The current style is to start function names with lower case and they
should be verb phrases
(http://llvm.org/docs/CodingStandards.html#name-types-functions-variables-and-enumerators-properly),
so please use something like getLogBase2Vector.
It looks like the function is only ever used with ConstantDataVector,
so please use
static Constant *getLogBase2Vector(const ConstantDataVector *C)
as the signature and simplify.
Cheers,
Rafael
More information about the llvm-commits
mailing list