diff --git a/.gitignore b/.gitignore index 6bf71eb0..23f2926b 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,6 @@ /.build /Packages Package.resolved +Package.pins /*.xcodeproj /build diff --git a/Sources/LLVM/IRBuilder.swift b/Sources/LLVM/IRBuilder.swift index 351e41ef..42339b07 100644 --- a/Sources/LLVM/IRBuilder.swift +++ b/Sources/LLVM/IRBuilder.swift @@ -497,9 +497,11 @@ public class IRBuilder { public func buildAdd(_ lhs: IRValue, _ rhs: IRValue, overflowBehavior: OverflowBehavior = .default, name: String = "") -> IRValue { + let lhsType = lowerVector(lhs.type) + let lhsVal = lhs.asLLVM() let rhsVal = rhs.asLLVM() - if lhs.type is IntType { + if lhsType is IntType { switch overflowBehavior { case .noSignedWrap: return LLVMBuildNSWAdd(llvm, lhsVal, rhsVal, name) @@ -508,7 +510,7 @@ public class IRBuilder { case .default: return LLVMBuildAdd(llvm, lhsVal, rhsVal, name) } - } else if lhs.type is FloatType { + } else if lhsType is FloatType { return LLVMBuildFAdd(llvm, lhsVal, rhsVal, name) } fatalError("Can only add value of int, float, or vector types") @@ -530,9 +532,11 @@ public class IRBuilder { public func buildSub(_ lhs: IRValue, _ rhs: IRValue, overflowBehavior: OverflowBehavior = .default, name: String = "") -> IRValue { + let lhsType = lowerVector(lhs.type) + let lhsVal = lhs.asLLVM() let rhsVal = rhs.asLLVM() - if lhs.type is IntType { + if lhsType is IntType { switch overflowBehavior { case .noSignedWrap: return LLVMBuildNSWSub(llvm, lhsVal, rhsVal, name) @@ -541,7 +545,7 @@ public class IRBuilder { case .default: return LLVMBuildSub(llvm, lhsVal, rhsVal, name) } - } else if lhs.type is FloatType { + } else if lhsType is FloatType { return LLVMBuildFSub(llvm, lhsVal, rhsVal, name) } fatalError("Can only subtract value of int or float types") @@ -563,9 +567,11 @@ public class IRBuilder { public func buildMul(_ lhs: IRValue, _ rhs: IRValue, overflowBehavior: OverflowBehavior = .default, name: String = "") -> IRValue { + let lhsType = lowerVector(lhs.type) + let lhsVal = lhs.asLLVM() let rhsVal = rhs.asLLVM() - if lhs.type is IntType { + if lhsType is IntType { switch overflowBehavior { case .noSignedWrap: return LLVMBuildNSWMul(llvm, lhsVal, rhsVal, name) @@ -574,7 +580,7 @@ public class IRBuilder { case .default: return LLVMBuildMul(llvm, lhsVal, rhsVal, name) } - } else if lhs.type is FloatType { + } else if lhsType is FloatType { return LLVMBuildFMul(llvm, lhsVal, rhsVal, name) } fatalError("Can only multiply value of int or float types") @@ -598,15 +604,17 @@ public class IRBuilder { public func buildRem(_ lhs: IRValue, _ rhs: IRValue, signed: Bool = true, name: String = "") -> IRValue { + let lhsType = lowerVector(lhs.type) + let lhsVal = lhs.asLLVM() let rhsVal = rhs.asLLVM() - if lhs.type is IntType { + if lhsType is IntType { if signed { return LLVMBuildSRem(llvm, lhsVal, rhsVal, name) } else { return LLVMBuildURem(llvm, lhsVal, rhsVal, name) } - } else if lhs.type is FloatType { + } else if lhsType is FloatType { return LLVMBuildFRem(llvm, lhsVal, rhsVal, name) } fatalError("Can only take remainder of int or float types") @@ -633,9 +641,11 @@ public class IRBuilder { public func buildDiv(_ lhs: IRValue, _ rhs: IRValue, signed: Bool = true, exact: Bool = false, name: String = "") -> IRValue { + let lhsType = lowerVector(lhs.type) + let lhsVal = lhs.asLLVM() let rhsVal = rhs.asLLVM() - if lhs.type is IntType { + if lhsType is IntType { if signed { if exact { return LLVMBuildExactSDiv(llvm, lhsVal, rhsVal, name) @@ -645,7 +655,7 @@ public class IRBuilder { } else { return LLVMBuildUDiv(llvm, lhsVal, rhsVal, name) } - } else if lhs.type is FloatType { + } else if lhsType is FloatType { return LLVMBuildFDiv(llvm, lhsVal, rhsVal, name) } fatalError("Can only divide values of int or float types") @@ -694,9 +704,11 @@ public class IRBuilder { public func buildFCmp(_ lhs: IRValue, _ rhs: IRValue, _ predicate: RealPredicate, name: String = "") -> IRValue { + let lhsType = lowerVector(lhs.type) + let lhsVal = lhs.asLLVM() let rhsVal = rhs.asLLVM() - guard lhs.type is FloatType else { + guard lhsType is FloatType else { fatalError("Can only build FCMP instruction with float types") } return LLVMBuildFCmp(llvm, predicate.llvm, lhsVal, rhsVal, name) @@ -1770,3 +1782,11 @@ public class IRBuilder { LLVMDisposeBuilder(llvm) } } + +private func lowerVector(_ type: IRType) -> IRType { + guard let vectorType = type as? VectorType else { + return type + } + + return vectorType.elementType +}