[PATCH] D41233: [InstCombine] Canonizing 'and' before 'shl'
Sanjay Patel via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Dec 16 09:32:42 PST 2017
spatel added a comment.
At least the bswap part of this (and probably handling the regression that @craig.topper pointed out) should be split into independent patches. I don't know what the InstSimplify part is doing yet, but that seems like it should be an independent patch too.
You can see the bswap limitation with a small test like this:
declare void @extra_use(i32)
define i32 @test7_and_first(i32 %x) {
%shl = shl i32 %x, 16
%shr = lshr i32 %x, 16
%or = or i32 %shl, %shr
%t1 = and i32 %or, 16711935
%shl3 = shl nuw i32 %t1, 8
%and4 = lshr i32 %or, 8
%shr5 = and i32 %and4, 16711935
%or6 = or i32 %shl3, %shr5
ret i32 %or6
}
define i32 @test7_and_first_extra_use(i32 %x) {
%shl = shl i32 %x, 16
%shr = lshr i32 %x, 16
%or = or i32 %shl, %shr
%t1 = and i32 %or, 16711935
%shl3 = shl nuw i32 %t1, 8
%and4 = lshr i32 %or, 8
%shr5 = and i32 %and4, 16711935
%or6 = or i32 %shl3, %shr5
call void @extra_use(i32 %t1)
ret i32 %or6
}
define i32 @test7_shl_first(i32 %x) {
%shl = shl i32 %x, 16
%shr = lshr i32 %x, 16
%or = or i32 %shl, %shr
%and2 = shl i32 %or, 8
%shl3 = and i32 %and2, -16711936
%and4 = lshr i32 %or, 8
%shr5 = and i32 %and4, 16711935
%or6 = or i32 %shl3, %shr5
ret i32 %or6
}
$ ./opt -instcombine -S bswap.ll
declare void @extra_use(i32)
define i32 @test7_and_first(i32 %x) {
%or6 = call i32 @llvm.bswap.i32(i32 %x)
ret i32 %or6
}
define i32 @test7_and_first_extra_use(i32 %x) {
%shl = shl i32 %x, 16
%shr = lshr i32 %x, 16
%or = or i32 %shl, %shr
%t1 = and i32 %or, 16711935
%shl3 = shl nuw i32 %t1, 8
%and4 = lshr i32 %or, 8
%shr5 = and i32 %and4, 16711935
%or6 = or i32 %shl3, %shr5
call void @extra_use(i32 %t1)
ret i32 %or6
}
define i32 @test7_shl_first(i32 %x) {
%or6 = call i32 @llvm.bswap.i32(i32 %x)
ret i32 %or6
}
Repository:
rL LLVM
https://reviews.llvm.org/D41233
More information about the llvm-commits
mailing list