[PATCH] D20774: [InstCombine] look through bitcasts to find selects
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 1 17:56:36 PDT 2016
spatel added a comment.
It's going to take multiple patches/steps to get this to match in the DAG. Is there any concern about making the following transform in IR:
Before:
define <2 x i64> @gibson(<2 x i64> %a, <2 x i64> %b) {
%t0 = bitcast <2 x i64> %a to <4 x i32>
%t1 = bitcast <2 x i64> %b to <4 x i32>
%cmp = icmp sgt <4 x i32> %t0, %t1
%sext = sext <4 x i1> %cmp to <4 x i32>
%t2 = bitcast <4 x i32> %sext to <2 x i64>
%and = and <2 x i64> %t2, %a
%neg = xor <4 x i32> %sext, <i32 -1, i32 -1, i32 -1, i32 -1>
%neg2 = bitcast <4 x i32> %neg to <2 x i64>
%and2 = and <2 x i64> %neg2, %b
%or = or <2 x i64> %and, %and2
ret <2 x i64> %or
}
After:
define <2 x i64> @max(<2 x i64> %a, <2 x i64> %b) {
%t0 = bitcast <2 x i64> %a to <4 x i32>
%t1 = bitcast <2 x i64> %b to <4 x i32>
%cmp = icmp sgt <4 x i32> %t0, %t1
%or = select <4 x i1> %cmp, <4 x i32> %t0, <4 x i32> %t1
%r1 = bitcast <4 x i32> %or to <2 x i64>
ret <2 x i64> %r1
}
We're trading 4 logic ops, a bitcast, and a sext for a select. Is that better / more canonical IR for all targets?
http://reviews.llvm.org/D20774
More information about the llvm-commits
mailing list