Hi all, is there any way to compare two 128bit values? I have tried 3 different approaches and they all fail with an internal assertion. I'm running llvm 2.4 on x86 with the following command line: > llvm-as test.ll -o test.bc > llc test.bc -filetype=asm I would expect the code generator to emit a sequence of SSE instructions. --------------------------------------------------------------------------------------- Approach 1 ---------------- define i1 @VectorCompare1(<4 x i32> %x, <4 x i32> %y) { %1 = icmp eq <4 x i32> %x, %y %2 = bitcast <4 x i1> %1 to i4 %3 = icmp eq i4 %2, 0 ret i1 %3 } This fails with: ssertion failed: (VT.getSizeInBits() == Operand.getValueType().getSizeInBits() && "Cannot BIT_CONVERT between types of different sizes!"), function getNode, file SelectionDAG.cpp, line 2218. Approach 2 ---------------- define i1 @VectorCompare2(<4 x i32> %x, <4 x i32> %y) { %1 = icmp eq <4 x i32> %x, %y %2 = extractelement <4 x i1> %1, i32 0 %3 = extractelement <4 x i1> %1, i32 1 %4 = extractelement <4 x i1> %1, i32 2 %5 = extractelement <4 x i1> %1, i32 3 %6 = or i1 %2, %3 %7 = or i1 %4, %5 %8 = or i1 %6, %7 ret i1 %8 } This fails with: Assertion failed: (isVector() && "Invalid vector type!"), function getVectorNumElements, file /Users/cbasile/src/llvm-2.4/include/llvm/ CodeGen/ValueTypes.h, line 339. Approach 3 ---------------- define i1 @VectorCompare3(i128 %x, i128 %y) { %1 = icmp eq i128 %x, %y ret i1 %1 } This fails with: Cannot yet select: 0x10182b4: i8 = setcc 0x101844c, 0x10184d4, 0x100becc --------------------------------------------------------------------------------------- I'd really appreciate if someone could help me with this. Thanks Claudio
On Thu, Dec 25, 2008 at 1:28 AM, Claudio Basile <cbasile at tempo-da.com> wrote:> Hi all, > > is there any way to compare two 128bit values? > I have tried 3 different approaches and they all fail with an internal > assertion. > I'm running llvm 2.4 on x86 with the following command line: > > > llvm-as test.ll -o test.bc > > llc test.bc -filetype=asm > > I would expect the code generator to emit a sequence of SSE > instructions.Approaches 1 and 2 depend on some stuff that hasn't really stabilized yet... you should get much better results with vicmp.> define i1 @VectorCompare3(i128 %x, i128 %y) { > %1 = icmp eq i128 %x, %y > ret i1 %1 > } > > This fails with: > > Cannot yet select: 0x10182b4: i8 = setcc 0x101844c, 0x10184d4, 0x100beccThe result isn't pretty, but this appears to work on x86 using a recent SVN build... I wouldn't be surprised if this was fixed post-2.4. -Eli
On Thu, Dec 25, 2008 at 1:54 AM, Eli Friedman <eli.friedman at gmail.com> wrote:> On Thu, Dec 25, 2008 at 1:28 AM, Claudio Basile <cbasile at tempo-da.com> wrote: >> Hi all, >> >> is there any way to compare two 128bit values? >> I have tried 3 different approaches and they all fail with an internal >> assertion. >> I'm running llvm 2.4 on x86 with the following command line: >> >> > llvm-as test.ll -o test.bc >> > llc test.bc -filetype=asm >> >> I would expect the code generator to emit a sequence of SSE >> instructions. > > Approaches 1 and 2 depend on some stuff that hasn't really stabilized > yet... you should get much better results with vicmp.Oh wait, I just realized vicmp is a post-2.4 thing... if you really want to generate an SSE comparison using LLVM 2.4, you can use the x86 intrinsics, like @llvm.x86.sse2.pcmpeq.b. -Eli