@@ -288,9 +288,8 @@ static bool processPHI(PHINode *P, LazyValueInfo *LVI, DominatorTree *DT,
288
288
}
289
289
290
290
static bool processICmp (ICmpInst *Cmp, LazyValueInfo *LVI) {
291
- // Only for signed relational comparisons of scalar integers.
292
- if (Cmp->getType ()->isVectorTy () ||
293
- !Cmp->getOperand (0 )->getType ()->isIntegerTy ())
291
+ // Only for signed relational comparisons of integers.
292
+ if (!Cmp->getOperand (0 )->getType ()->isIntOrIntVectorTy ())
294
293
return false ;
295
294
296
295
if (!Cmp->isSigned ())
@@ -505,12 +504,8 @@ static bool processBinOp(BinaryOperator *BinOp, LazyValueInfo *LVI);
505
504
// because it is negation-invariant.
506
505
static bool processAbsIntrinsic (IntrinsicInst *II, LazyValueInfo *LVI) {
507
506
Value *X = II->getArgOperand (0 );
508
- Type *Ty = X->getType ();
509
- if (!Ty->isIntegerTy ())
510
- return false ;
511
-
512
507
bool IsIntMinPoison = cast<ConstantInt>(II->getArgOperand (1 ))->isOne ();
513
- APInt IntMin = APInt::getSignedMinValue (Ty ->getScalarSizeInBits ());
508
+ APInt IntMin = APInt::getSignedMinValue (X-> getType () ->getScalarSizeInBits ());
514
509
ConstantRange Range = LVI->getConstantRangeAtUse (
515
510
II->getOperandUse (0 ), /* UndefAllowed*/ IsIntMinPoison);
516
511
@@ -679,15 +674,13 @@ static bool processCallSite(CallBase &CB, LazyValueInfo *LVI) {
679
674
}
680
675
681
676
if (auto *WO = dyn_cast<WithOverflowInst>(&CB)) {
682
- if (WO-> getLHS ()-> getType ()-> isIntegerTy () && willNotOverflow (WO, LVI)) {
677
+ if (willNotOverflow (WO, LVI))
683
678
return processOverflowIntrinsic (WO, LVI);
684
- }
685
679
}
686
680
687
681
if (auto *SI = dyn_cast<SaturatingInst>(&CB)) {
688
- if (SI-> getType ()-> isIntegerTy () && willNotOverflow (SI, LVI)) {
682
+ if (willNotOverflow (SI, LVI))
689
683
return processSaturatingInst (SI, LVI);
690
- }
691
684
}
692
685
693
686
bool Changed = false ;
@@ -761,11 +754,10 @@ static bool narrowSDivOrSRem(BinaryOperator *Instr, const ConstantRange &LCR,
761
754
const ConstantRange &RCR) {
762
755
assert (Instr->getOpcode () == Instruction::SDiv ||
763
756
Instr->getOpcode () == Instruction::SRem);
764
- assert (!Instr->getType ()->isVectorTy ());
765
757
766
758
// Find the smallest power of two bitwidth that's sufficient to hold Instr's
767
759
// operands.
768
- unsigned OrigWidth = Instr->getType ()->getIntegerBitWidth ();
760
+ unsigned OrigWidth = Instr->getType ()->getScalarSizeInBits ();
769
761
770
762
// What is the smallest bit width that can accommodate the entire value ranges
771
763
// of both of the operands?
@@ -788,7 +780,7 @@ static bool narrowSDivOrSRem(BinaryOperator *Instr, const ConstantRange &LCR,
788
780
789
781
++NumSDivSRemsNarrowed;
790
782
IRBuilder<> B{Instr};
791
- auto *TruncTy = Type::getIntNTy ( Instr->getContext (), NewWidth);
783
+ auto *TruncTy = Instr->getType ()-> getWithNewBitWidth ( NewWidth);
792
784
auto *LHS = B.CreateTruncOrBitCast (Instr->getOperand (0 ), TruncTy,
793
785
Instr->getName () + " .lhs.trunc" );
794
786
auto *RHS = B.CreateTruncOrBitCast (Instr->getOperand (1 ), TruncTy,
@@ -809,7 +801,6 @@ static bool expandUDivOrURem(BinaryOperator *Instr, const ConstantRange &XCR,
809
801
Type *Ty = Instr->getType ();
810
802
assert (Instr->getOpcode () == Instruction::UDiv ||
811
803
Instr->getOpcode () == Instruction::URem);
812
- assert (!Ty->isVectorTy ());
813
804
bool IsRem = Instr->getOpcode () == Instruction::URem;
814
805
815
806
Value *X = Instr->getOperand (0 );
@@ -892,7 +883,6 @@ static bool narrowUDivOrURem(BinaryOperator *Instr, const ConstantRange &XCR,
892
883
const ConstantRange &YCR) {
893
884
assert (Instr->getOpcode () == Instruction::UDiv ||
894
885
Instr->getOpcode () == Instruction::URem);
895
- assert (!Instr->getType ()->isVectorTy ());
896
886
897
887
// Find the smallest power of two bitwidth that's sufficient to hold Instr's
898
888
// operands.
@@ -905,12 +895,12 @@ static bool narrowUDivOrURem(BinaryOperator *Instr, const ConstantRange &XCR,
905
895
906
896
// NewWidth might be greater than OrigWidth if OrigWidth is not a power of
907
897
// two.
908
- if (NewWidth >= Instr->getType ()->getIntegerBitWidth ())
898
+ if (NewWidth >= Instr->getType ()->getScalarSizeInBits ())
909
899
return false ;
910
900
911
901
++NumUDivURemsNarrowed;
912
902
IRBuilder<> B{Instr};
913
- auto *TruncTy = Type::getIntNTy ( Instr->getContext (), NewWidth);
903
+ auto *TruncTy = Instr->getType ()-> getWithNewBitWidth ( NewWidth);
914
904
auto *LHS = B.CreateTruncOrBitCast (Instr->getOperand (0 ), TruncTy,
915
905
Instr->getName () + " .lhs.trunc" );
916
906
auto *RHS = B.CreateTruncOrBitCast (Instr->getOperand (1 ), TruncTy,
@@ -929,9 +919,6 @@ static bool narrowUDivOrURem(BinaryOperator *Instr, const ConstantRange &XCR,
929
919
static bool processUDivOrURem (BinaryOperator *Instr, LazyValueInfo *LVI) {
930
920
assert (Instr->getOpcode () == Instruction::UDiv ||
931
921
Instr->getOpcode () == Instruction::URem);
932
- if (Instr->getType ()->isVectorTy ())
933
- return false ;
934
-
935
922
ConstantRange XCR = LVI->getConstantRangeAtUse (Instr->getOperandUse (0 ),
936
923
/* UndefAllowed*/ false );
937
924
// Allow undef for RHS, as we can assume it is division by zero UB.
@@ -946,7 +933,6 @@ static bool processUDivOrURem(BinaryOperator *Instr, LazyValueInfo *LVI) {
946
933
static bool processSRem (BinaryOperator *SDI, const ConstantRange &LCR,
947
934
const ConstantRange &RCR, LazyValueInfo *LVI) {
948
935
assert (SDI->getOpcode () == Instruction::SRem);
949
- assert (!SDI->getType ()->isVectorTy ());
950
936
951
937
if (LCR.abs ().icmp (CmpInst::ICMP_ULT, RCR.abs ())) {
952
938
SDI->replaceAllUsesWith (SDI->getOperand (0 ));
@@ -1006,7 +992,6 @@ static bool processSRem(BinaryOperator *SDI, const ConstantRange &LCR,
1006
992
static bool processSDiv (BinaryOperator *SDI, const ConstantRange &LCR,
1007
993
const ConstantRange &RCR, LazyValueInfo *LVI) {
1008
994
assert (SDI->getOpcode () == Instruction::SDiv);
1009
- assert (!SDI->getType ()->isVectorTy ());
1010
995
1011
996
// Check whether the division folds to a constant.
1012
997
ConstantRange DivCR = LCR.sdiv (RCR);
@@ -1064,9 +1049,6 @@ static bool processSDiv(BinaryOperator *SDI, const ConstantRange &LCR,
1064
1049
static bool processSDivOrSRem (BinaryOperator *Instr, LazyValueInfo *LVI) {
1065
1050
assert (Instr->getOpcode () == Instruction::SDiv ||
1066
1051
Instr->getOpcode () == Instruction::SRem);
1067
- if (Instr->getType ()->isVectorTy ())
1068
- return false ;
1069
-
1070
1052
ConstantRange LCR =
1071
1053
LVI->getConstantRangeAtUse (Instr->getOperandUse (0 ), /* AllowUndef*/ false );
1072
1054
// Allow undef for RHS, as we can assume it is division by zero UB.
@@ -1085,12 +1067,9 @@ static bool processSDivOrSRem(BinaryOperator *Instr, LazyValueInfo *LVI) {
1085
1067
}
1086
1068
1087
1069
static bool processAShr (BinaryOperator *SDI, LazyValueInfo *LVI) {
1088
- if (SDI->getType ()->isVectorTy ())
1089
- return false ;
1090
-
1091
1070
ConstantRange LRange =
1092
1071
LVI->getConstantRangeAtUse (SDI->getOperandUse (0 ), /* UndefAllowed*/ false );
1093
- unsigned OrigWidth = SDI->getType ()->getIntegerBitWidth ();
1072
+ unsigned OrigWidth = SDI->getType ()->getScalarSizeInBits ();
1094
1073
ConstantRange NegOneOrZero =
1095
1074
ConstantRange (APInt (OrigWidth, (uint64_t )-1 , true ), APInt (OrigWidth, 1 ));
1096
1075
if (NegOneOrZero.contains (LRange)) {
@@ -1117,9 +1096,6 @@ static bool processAShr(BinaryOperator *SDI, LazyValueInfo *LVI) {
1117
1096
}
1118
1097
1119
1098
static bool processSExt (SExtInst *SDI, LazyValueInfo *LVI) {
1120
- if (SDI->getType ()->isVectorTy ())
1121
- return false ;
1122
-
1123
1099
const Use &Base = SDI->getOperandUse (0 );
1124
1100
if (!LVI->getConstantRangeAtUse (Base, /* UndefAllowed*/ false )
1125
1101
.isAllNonNegative ())
@@ -1138,9 +1114,6 @@ static bool processSExt(SExtInst *SDI, LazyValueInfo *LVI) {
1138
1114
}
1139
1115
1140
1116
static bool processPossibleNonNeg (PossiblyNonNegInst *I, LazyValueInfo *LVI) {
1141
- if (I->getType ()->isVectorTy ())
1142
- return false ;
1143
-
1144
1117
if (I->hasNonNeg ())
1145
1118
return false ;
1146
1119
@@ -1164,9 +1137,6 @@ static bool processUIToFP(UIToFPInst *UIToFP, LazyValueInfo *LVI) {
1164
1137
}
1165
1138
1166
1139
static bool processSIToFP (SIToFPInst *SIToFP, LazyValueInfo *LVI) {
1167
- if (SIToFP->getType ()->isVectorTy ())
1168
- return false ;
1169
-
1170
1140
const Use &Base = SIToFP->getOperandUse (0 );
1171
1141
if (!LVI->getConstantRangeAtUse (Base, /* UndefAllowed*/ false )
1172
1142
.isAllNonNegative ())
@@ -1187,9 +1157,6 @@ static bool processSIToFP(SIToFPInst *SIToFP, LazyValueInfo *LVI) {
1187
1157
static bool processBinOp (BinaryOperator *BinOp, LazyValueInfo *LVI) {
1188
1158
using OBO = OverflowingBinaryOperator;
1189
1159
1190
- if (BinOp->getType ()->isVectorTy ())
1191
- return false ;
1192
-
1193
1160
bool NSW = BinOp->hasNoSignedWrap ();
1194
1161
bool NUW = BinOp->hasNoUnsignedWrap ();
1195
1162
if (NSW && NUW)
0 commit comments