@@ -62,6 +62,7 @@ STATISTIC(NumAShrsConverted, "Number of ashr converted to lshr");
62
62
STATISTIC (NumAShrsRemoved, " Number of ashr removed" );
63
63
STATISTIC (NumSRems, " Number of srem converted to urem" );
64
64
STATISTIC (NumSExt, " Number of sext converted to zext" );
65
+ STATISTIC (NumSIToFP, " Number of sitofp converted to uitofp" );
65
66
STATISTIC (NumSICmps, " Number of signed icmp preds simplified to unsigned" );
66
67
STATISTIC (NumAnd, " Number of ands removed" );
67
68
STATISTIC (NumNW, " Number of no-wrap deductions" );
@@ -89,7 +90,7 @@ STATISTIC(NumSMinMax,
89
90
" Number of llvm.s{min,max} intrinsics simplified to unsigned" );
90
91
STATISTIC (NumUDivURemsNarrowedExpanded,
91
92
" Number of bound udiv's/urem's expanded" );
92
- STATISTIC (NumZExt , " Number of non-negative deductions" );
93
+ STATISTIC (NumNNeg , " Number of zext/uitofp non-negative deductions" );
93
94
94
95
static Constant *getConstantAt (Value *V, Instruction *At, LazyValueInfo *LVI) {
95
96
if (Constant *C = LVI->getConstant (V, At))
@@ -1075,20 +1076,49 @@ static bool processSExt(SExtInst *SDI, LazyValueInfo *LVI) {
1075
1076
return true ;
1076
1077
}
1077
1078
1078
- static bool processZExt (ZExtInst *ZExt , LazyValueInfo *LVI) {
1079
- if (ZExt ->getType ()->isVectorTy ())
1079
+ static bool processPossibleNonNeg (PossiblyNonNegInst *I , LazyValueInfo *LVI) {
1080
+ if (I ->getType ()->isVectorTy ())
1080
1081
return false ;
1081
1082
1082
- if (ZExt ->hasNonNeg ())
1083
+ if (I ->hasNonNeg ())
1083
1084
return false ;
1084
1085
1085
- const Use &Base = ZExt ->getOperandUse (0 );
1086
+ const Use &Base = I ->getOperandUse (0 );
1086
1087
if (!LVI->getConstantRangeAtUse (Base, /* UndefAllowed*/ false )
1087
1088
.isAllNonNegative ())
1088
1089
return false ;
1089
1090
1090
- ++NumZExt;
1091
- ZExt->setNonNeg ();
1091
+ ++NumNNeg;
1092
+ I->setNonNeg ();
1093
+
1094
+ return true ;
1095
+ }
1096
+
1097
+ static bool processZExt (ZExtInst *ZExt, LazyValueInfo *LVI) {
1098
+ return processPossibleNonNeg (cast<PossiblyNonNegInst>(ZExt), LVI);
1099
+ }
1100
+
1101
+ static bool processUIToFP (UIToFPInst *UIToFP, LazyValueInfo *LVI) {
1102
+ return processPossibleNonNeg (cast<PossiblyNonNegInst>(UIToFP), LVI);
1103
+ }
1104
+
1105
+ static bool processSIToFP (SIToFPInst *SIToFP, LazyValueInfo *LVI) {
1106
+ if (SIToFP->getType ()->isVectorTy ())
1107
+ return false ;
1108
+
1109
+ const Use &Base = SIToFP->getOperandUse (0 );
1110
+ if (!LVI->getConstantRangeAtUse (Base, /* UndefAllowed*/ false )
1111
+ .isAllNonNegative ())
1112
+ return false ;
1113
+
1114
+ ++NumSIToFP;
1115
+ auto *UIToFP = CastInst::Create (Instruction::UIToFP, Base, SIToFP->getType (),
1116
+ " " , SIToFP->getIterator ());
1117
+ UIToFP->takeName (SIToFP);
1118
+ UIToFP->setDebugLoc (SIToFP->getDebugLoc ());
1119
+ UIToFP->setNonNeg ();
1120
+ SIToFP->replaceAllUsesWith (UIToFP);
1121
+ SIToFP->eraseFromParent ();
1092
1122
1093
1123
return true ;
1094
1124
}
@@ -1197,6 +1227,12 @@ static bool runImpl(Function &F, LazyValueInfo *LVI, DominatorTree *DT,
1197
1227
case Instruction::ZExt:
1198
1228
BBChanged |= processZExt (cast<ZExtInst>(&II), LVI);
1199
1229
break ;
1230
+ case Instruction::UIToFP:
1231
+ BBChanged |= processUIToFP (cast<UIToFPInst>(&II), LVI);
1232
+ break ;
1233
+ case Instruction::SIToFP:
1234
+ BBChanged |= processSIToFP (cast<SIToFPInst>(&II), LVI);
1235
+ break ;
1200
1236
case Instruction::Add:
1201
1237
case Instruction::Sub:
1202
1238
case Instruction::Mul:
0 commit comments