[llvm] r319419 - Support generic lowering of vector bswap
Serge Guelton via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 30 03:06:22 PST 2017
Author: serge_sans_paille
Date: Thu Nov 30 03:06:22 2017
New Revision: 319419
URL: http://llvm.org/viewvc/llvm-project?rev=319419&view=rev
Log:
Support generic lowering of vector bswap
Added:
llvm/trunk/test/CodeGen/Generic/bswap.ll
Modified:
llvm/trunk/lib/CodeGen/IntrinsicLowering.cpp
Modified: llvm/trunk/lib/CodeGen/IntrinsicLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/IntrinsicLowering.cpp?rev=319419&r1=319418&r2=319419&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/IntrinsicLowering.cpp (original)
+++ llvm/trunk/lib/CodeGen/IntrinsicLowering.cpp Thu Nov 30 03:06:22 2017
@@ -164,9 +164,9 @@ void IntrinsicLowering::AddPrototypes(Mo
/// LowerBSWAP - Emit the code to lower bswap of V before the specified
/// instruction IP.
static Value *LowerBSWAP(LLVMContext &Context, Value *V, Instruction *IP) {
- assert(V->getType()->isIntegerTy() && "Can't bswap a non-integer type!");
+ assert(V->getType()->isIntOrIntVectorTy() && "Can't bswap a non-integer type!");
- unsigned BitSize = V->getType()->getPrimitiveSizeInBits();
+ unsigned BitSize = V->getType()->getScalarSizeInBits();
IRBuilder<> Builder(IP);
@@ -190,10 +190,10 @@ static Value *LowerBSWAP(LLVMContext &Co
Value *Tmp1 = Builder.CreateLShr(V,ConstantInt::get(V->getType(), 24),
"bswap.1");
Tmp3 = Builder.CreateAnd(Tmp3,
- ConstantInt::get(Type::getInt32Ty(Context), 0xFF0000),
+ ConstantInt::get(V->getType(), 0xFF0000),
"bswap.and3");
Tmp2 = Builder.CreateAnd(Tmp2,
- ConstantInt::get(Type::getInt32Ty(Context), 0xFF00),
+ ConstantInt::get(V->getType(), 0xFF00),
"bswap.and2");
Tmp4 = Builder.CreateOr(Tmp4, Tmp3, "bswap.or1");
Tmp2 = Builder.CreateOr(Tmp2, Tmp1, "bswap.or2");
@@ -221,27 +221,27 @@ static Value *LowerBSWAP(LLVMContext &Co
ConstantInt::get(V->getType(), 56),
"bswap.1");
Tmp7 = Builder.CreateAnd(Tmp7,
- ConstantInt::get(Type::getInt64Ty(Context),
+ ConstantInt::get(V->getType(),
0xFF000000000000ULL),
"bswap.and7");
Tmp6 = Builder.CreateAnd(Tmp6,
- ConstantInt::get(Type::getInt64Ty(Context),
+ ConstantInt::get(V->getType(),
0xFF0000000000ULL),
"bswap.and6");
Tmp5 = Builder.CreateAnd(Tmp5,
- ConstantInt::get(Type::getInt64Ty(Context),
+ ConstantInt::get(V->getType(),
0xFF00000000ULL),
"bswap.and5");
Tmp4 = Builder.CreateAnd(Tmp4,
- ConstantInt::get(Type::getInt64Ty(Context),
+ ConstantInt::get(V->getType(),
0xFF000000ULL),
"bswap.and4");
Tmp3 = Builder.CreateAnd(Tmp3,
- ConstantInt::get(Type::getInt64Ty(Context),
+ ConstantInt::get(V->getType(),
0xFF0000ULL),
"bswap.and3");
Tmp2 = Builder.CreateAnd(Tmp2,
- ConstantInt::get(Type::getInt64Ty(Context),
+ ConstantInt::get(V->getType(),
0xFF00ULL),
"bswap.and2");
Tmp8 = Builder.CreateOr(Tmp8, Tmp7, "bswap.or1");
Added: llvm/trunk/test/CodeGen/Generic/bswap.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Generic/bswap.ll?rev=319419&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/Generic/bswap.ll (added)
+++ llvm/trunk/test/CodeGen/Generic/bswap.ll Thu Nov 30 03:06:22 2017
@@ -0,0 +1,50 @@
+; tests lowering of vector bswap
+; RUN: lli -force-interpreter %s | FileCheck %s
+
+; CHECK: 0x100
+; CHECK: 0x10000
+; CHECK: 0x1001000000000000
+; CHECK: 0x100
+; CHECK: 0x10000
+; CHECK: 0x1001000000000000
+
+
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+
+declare i16 @llvm.bswap.i16(i16);
+declare i32 @llvm.bswap.i32(i32);
+declare i64 @llvm.bswap.i64(i64);
+declare <4 x i16> @llvm.bswap.v4i16(<4 x i16>);
+declare <4 x i32> @llvm.bswap.v4i32(<4 x i32>);
+declare <4 x i64> @llvm.bswap.v4i64(<4 x i64>);
+declare i32 @printf(i8* nocapture readonly, ...);
+
+ at .str = private unnamed_addr constant [5 x i8] c"%#x\0A\00", align 1
+ at .strs = private unnamed_addr constant [6 x i8] c"%#hx\0A\00", align 1
+ at .strl = private unnamed_addr constant [6 x i8] c"%#lx\0A\00", align 1
+
+define i32 @main() local_unnamed_addr {
+ %ra = tail call i16 @llvm.bswap.i16(i16 1)
+ %pa = tail call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.strs, i64 0, i64 0), i16 %ra)
+
+ %rb = tail call i32 @llvm.bswap.i32(i32 256)
+ %pb = tail call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %rb)
+
+ %rc = tail call i64 @llvm.bswap.i64(i64 272)
+ %pc = tail call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.strl, i64 0, i64 0), i64 %rc)
+
+ %r0 = tail call <4 x i16> @llvm.bswap.v4i16(<4 x i16> <i16 1, i16 1, i16 1, i16 1>)
+ %e0 = extractelement <4 x i16> %r0, i8 0
+ %p0 = tail call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.strs, i64 0, i64 0), i16 %e0)
+
+ %r1 = tail call <4 x i32> @llvm.bswap.v4i32(<4 x i32> <i32 256, i32 256, i32 256, i32 256>)
+ %e1 = extractelement <4 x i32> %r1, i8 1
+ %p1 = tail call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %e1)
+
+ %r2 = tail call <4 x i64> @llvm.bswap.v4i64(<4 x i64> <i64 272, i64 272, i64 272, i64 272>)
+ %e2 = extractelement <4 x i64> %r2, i8 2
+ %p2 = tail call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.strl, i64 0, i64 0), i64 %e2)
+
+ ret i32 0
+}
More information about the llvm-commits
mailing list