@@ -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,50 @@ 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 (Instruction *I, LazyValueInfo *LVI) {
1080
+ assert (isa<PossiblyNonNegInst>(I) && " Requires PossiblyNonNeg instruction" );
1081
+ if (I->getType ()->isVectorTy ())
1080
1082
return false ;
1081
1083
1082
- if (ZExt ->hasNonNeg ())
1084
+ if (I ->hasNonNeg ())
1083
1085
return false ;
1084
1086
1085
- const Use &Base = ZExt ->getOperandUse (0 );
1087
+ const Use &Base = I ->getOperandUse (0 );
1086
1088
if (!LVI->getConstantRangeAtUse (Base, /* UndefAllowed*/ false )
1087
1089
.isAllNonNegative ())
1088
1090
return false ;
1089
1091
1090
- ++NumZExt;
1091
- ZExt->setNonNeg ();
1092
+ ++NumNNeg;
1093
+ I->setNonNeg ();
1094
+
1095
+ return true ;
1096
+ }
1097
+
1098
+ static bool processZExt (ZExtInst *ZExt, LazyValueInfo *LVI) {
1099
+ return processPossibleNonNeg (ZExt, LVI);
1100
+ }
1101
+
1102
+ static bool processUIToFP (UIToFPInst *UIToFP, LazyValueInfo *LVI) {
1103
+ return processPossibleNonNeg (UIToFP, LVI);
1104
+ }
1105
+
1106
+ static bool processSIToFP (SIToFPInst *SIToFP, LazyValueInfo *LVI) {
1107
+ if (SIToFP->getType ()->isVectorTy ())
1108
+ return false ;
1109
+
1110
+ const Use &Base = SIToFP->getOperandUse (0 );
1111
+ if (!LVI->getConstantRangeAtUse (Base, /* UndefAllowed*/ false )
1112
+ .isAllNonNegative ())
1113
+ return false ;
1114
+
1115
+ ++NumSIToFP;
1116
+ auto *UIToFP = CastInst::Create (Instruction::UIToFP, Base, SIToFP->getType (),
1117
+ " " , SIToFP->getIterator ());
1118
+ UIToFP->takeName (SIToFP);
1119
+ UIToFP->setDebugLoc (SIToFP->getDebugLoc ());
1120
+ UIToFP->setNonNeg ();
1121
+ SIToFP->replaceAllUsesWith (UIToFP);
1122
+ SIToFP->eraseFromParent ();
1092
1123
1093
1124
return true ;
1094
1125
}
@@ -1197,6 +1228,12 @@ static bool runImpl(Function &F, LazyValueInfo *LVI, DominatorTree *DT,
1197
1228
case Instruction::ZExt:
1198
1229
BBChanged |= processZExt (cast<ZExtInst>(&II), LVI);
1199
1230
break ;
1231
+ case Instruction::UIToFP:
1232
+ BBChanged |= processUIToFP (cast<UIToFPInst>(&II), LVI);
1233
+ break ;
1234
+ case Instruction::SIToFP:
1235
+ BBChanged |= processSIToFP (cast<SIToFPInst>(&II), LVI);
1236
+ break ;
1200
1237
case Instruction::Add:
1201
1238
case Instruction::Sub:
1202
1239
case Instruction::Mul:
0 commit comments