@@ -497,9 +497,11 @@ public class IRBuilder {
497
497
public func buildAdd( _ lhs: IRValue , _ rhs: IRValue ,
498
498
overflowBehavior: OverflowBehavior = . default,
499
499
name: String = " " ) -> IRValue {
500
+ let lhsType = lowerVector ( lhs. type)
501
+
500
502
let lhsVal = lhs. asLLVM ( )
501
503
let rhsVal = rhs. asLLVM ( )
502
- if lhs . type is IntType {
504
+ if lhsType is IntType {
503
505
switch overflowBehavior {
504
506
case . noSignedWrap:
505
507
return LLVMBuildNSWAdd ( llvm, lhsVal, rhsVal, name)
@@ -508,7 +510,7 @@ public class IRBuilder {
508
510
case . default:
509
511
return LLVMBuildAdd ( llvm, lhsVal, rhsVal, name)
510
512
}
511
- } else if lhs . type is FloatType {
513
+ } else if lhsType is FloatType {
512
514
return LLVMBuildFAdd ( llvm, lhsVal, rhsVal, name)
513
515
}
514
516
fatalError ( " Can only add value of int, float, or vector types " )
@@ -530,9 +532,11 @@ public class IRBuilder {
530
532
public func buildSub( _ lhs: IRValue , _ rhs: IRValue ,
531
533
overflowBehavior: OverflowBehavior = . default,
532
534
name: String = " " ) -> IRValue {
535
+ let lhsType = lowerVector ( lhs. type)
536
+
533
537
let lhsVal = lhs. asLLVM ( )
534
538
let rhsVal = rhs. asLLVM ( )
535
- if lhs . type is IntType {
539
+ if lhsType is IntType {
536
540
switch overflowBehavior {
537
541
case . noSignedWrap:
538
542
return LLVMBuildNSWSub ( llvm, lhsVal, rhsVal, name)
@@ -541,7 +545,7 @@ public class IRBuilder {
541
545
case . default:
542
546
return LLVMBuildSub ( llvm, lhsVal, rhsVal, name)
543
547
}
544
- } else if lhs . type is FloatType {
548
+ } else if lhsType is FloatType {
545
549
return LLVMBuildFSub ( llvm, lhsVal, rhsVal, name)
546
550
}
547
551
fatalError ( " Can only subtract value of int or float types " )
@@ -563,9 +567,11 @@ public class IRBuilder {
563
567
public func buildMul( _ lhs: IRValue , _ rhs: IRValue ,
564
568
overflowBehavior: OverflowBehavior = . default,
565
569
name: String = " " ) -> IRValue {
570
+ let lhsType = lowerVector ( lhs. type)
571
+
566
572
let lhsVal = lhs. asLLVM ( )
567
573
let rhsVal = rhs. asLLVM ( )
568
- if lhs . type is IntType {
574
+ if lhsType is IntType {
569
575
switch overflowBehavior {
570
576
case . noSignedWrap:
571
577
return LLVMBuildNSWMul ( llvm, lhsVal, rhsVal, name)
@@ -574,7 +580,7 @@ public class IRBuilder {
574
580
case . default:
575
581
return LLVMBuildMul ( llvm, lhsVal, rhsVal, name)
576
582
}
577
- } else if lhs . type is FloatType {
583
+ } else if lhsType is FloatType {
578
584
return LLVMBuildFMul ( llvm, lhsVal, rhsVal, name)
579
585
}
580
586
fatalError ( " Can only multiply value of int or float types " )
@@ -598,15 +604,17 @@ public class IRBuilder {
598
604
public func buildRem( _ lhs: IRValue , _ rhs: IRValue ,
599
605
signed: Bool = true ,
600
606
name: String = " " ) -> IRValue {
607
+ let lhsType = lowerVector ( lhs. type)
608
+
601
609
let lhsVal = lhs. asLLVM ( )
602
610
let rhsVal = rhs. asLLVM ( )
603
- if lhs . type is IntType {
611
+ if lhsType is IntType {
604
612
if signed {
605
613
return LLVMBuildSRem ( llvm, lhsVal, rhsVal, name)
606
614
} else {
607
615
return LLVMBuildURem ( llvm, lhsVal, rhsVal, name)
608
616
}
609
- } else if lhs . type is FloatType {
617
+ } else if lhsType is FloatType {
610
618
return LLVMBuildFRem ( llvm, lhsVal, rhsVal, name)
611
619
}
612
620
fatalError ( " Can only take remainder of int or float types " )
@@ -633,9 +641,11 @@ public class IRBuilder {
633
641
public func buildDiv( _ lhs: IRValue , _ rhs: IRValue ,
634
642
signed: Bool = true , exact: Bool = false ,
635
643
name: String = " " ) -> IRValue {
644
+ let lhsType = lowerVector ( lhs. type)
645
+
636
646
let lhsVal = lhs. asLLVM ( )
637
647
let rhsVal = rhs. asLLVM ( )
638
- if lhs . type is IntType {
648
+ if lhsType is IntType {
639
649
if signed {
640
650
if exact {
641
651
return LLVMBuildExactSDiv ( llvm, lhsVal, rhsVal, name)
@@ -645,7 +655,7 @@ public class IRBuilder {
645
655
} else {
646
656
return LLVMBuildUDiv ( llvm, lhsVal, rhsVal, name)
647
657
}
648
- } else if lhs . type is FloatType {
658
+ } else if lhsType is FloatType {
649
659
return LLVMBuildFDiv ( llvm, lhsVal, rhsVal, name)
650
660
}
651
661
fatalError ( " Can only divide values of int or float types " )
@@ -694,9 +704,11 @@ public class IRBuilder {
694
704
public func buildFCmp( _ lhs: IRValue , _ rhs: IRValue ,
695
705
_ predicate: RealPredicate ,
696
706
name: String = " " ) -> IRValue {
707
+ let lhsType = lowerVector ( lhs. type)
708
+
697
709
let lhsVal = lhs. asLLVM ( )
698
710
let rhsVal = rhs. asLLVM ( )
699
- guard lhs . type is FloatType else {
711
+ guard lhsType is FloatType else {
700
712
fatalError ( " Can only build FCMP instruction with float types " )
701
713
}
702
714
return LLVMBuildFCmp ( llvm, predicate. llvm, lhsVal, rhsVal, name)
@@ -1777,3 +1789,11 @@ public class IRBuilder {
1777
1789
LLVMDisposeBuilder ( llvm)
1778
1790
}
1779
1791
}
1792
+
1793
+ private func lowerVector( _ type: IRType ) -> IRType {
1794
+ guard let vectorType = type as? VectorType else {
1795
+ return type
1796
+ }
1797
+
1798
+ return vectorType. elementType
1799
+ }
0 commit comments