Skip to content

Commit

Permalink
Fixed vector pointer selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
BrettRToomey committed Nov 16, 2017
1 parent 70b4c4f commit 8c237f3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
13 changes: 10 additions & 3 deletions Sources/Core/IRGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1337,16 +1337,23 @@ extension IRGenerator {
case .staticLength(let length):
return i64.constant(length)
case .scalar(let index):
let vector = emit(expr: sel.rec, returnAddress: returnAddress)
var vector = emit(expr: sel.rec, returnAddress: returnAddress)
for _ in 0 ..< sel.levelsOfIndirection {
vector = b.buildLoad(vector)
}

if returnAddress {
return b.buildGEP(vector, indices: [i64.constant(0), i64.constant(index)])
}

return b.buildExtractElement(vector: vector, index: index)
case .swizzle(let indices):
let vector = emit(expr: sel.rec)
let recType = canonicalize(sel.rec.type)
var vector = emit(expr: sel.rec)
for _ in 0 ..< sel.levelsOfIndirection {
vector = b.buildLoad(vector)
}

let recType = canonicalize(findConcreteType(sel.rec.type))
let maskType = canonicalize(sel.type)
var shuffleMask = maskType.undef()
for (i, index) in indices.enumerated() {
Expand Down
9 changes: 9 additions & 0 deletions Sources/Core/Type.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ func findPolymorphic(_ type: Type) -> ty.Polymorphic? {
}
}

/// Unwraps a pointer (or nested pointers) until it finds a concrete type.
func findConcreteType(_ type: Type) -> Type {
guard let ptr = type as? ty.Pointer else {
return type
}

return findConcreteType(ptr.pointeeType)
}

/// Recursively searches polyType for a ty.Polymorphic to pair
/// with a matching argType. If found the ty.Polymorphic has
/// its specialization.val set for future use.
Expand Down

0 comments on commit 8c237f3

Please sign in to comment.