@@ -8182,89 +8182,65 @@ static Instruction *foldFCmpWithFloorAndCeil(FCmpInst &I,
8182
8182
InstCombinerImpl &CI) {
8183
8183
Value *LHS = I.getOperand (0 ), *RHS = I.getOperand (1 );
8184
8184
Type *OpType = LHS->getType ();
8185
- const CmpInst::Predicate Pred = I.getPredicate ();
8185
+ CmpInst::Predicate Pred = I.getPredicate ();
8186
8186
8187
8187
bool floor_x = match (LHS, m_Intrinsic<Intrinsic::floor>(m_Specific (RHS)));
8188
8188
bool x_floor = match (RHS, m_Intrinsic<Intrinsic::floor>(m_Specific (LHS)));
8189
8189
bool ceil_x = match (LHS, m_Intrinsic<Intrinsic::ceil>(m_Specific (RHS)));
8190
8190
bool x_ceil = match (RHS, m_Intrinsic<Intrinsic::ceil>(m_Specific (LHS)));
8191
8191
8192
+ if (x_floor || x_ceil) {
8193
+ std::swap (LHS, RHS);
8194
+ Pred = I.getSwappedPredicate ();
8195
+ (x_floor ? floor_x : ceil_x) = true ;
8196
+ }
8197
+
8192
8198
switch (Pred) {
8193
8199
case FCmpInst::FCMP_OLE:
8194
8200
// fcmp ole floor(x), x => fcmp ord x, 0
8195
- // fcmp ole x, ceil(x) => fcmp ord x, 0
8196
8201
if (floor_x)
8197
8202
return new FCmpInst (FCmpInst::FCMP_ORD, RHS, ConstantFP::getZero (OpType),
8198
8203
" " , &I);
8199
- if (x_ceil)
8200
- return new FCmpInst (FCmpInst::FCMP_ORD, LHS, ConstantFP::getZero (OpType),
8201
- " " , &I);
8202
8204
break ;
8203
8205
case FCmpInst::FCMP_OGT:
8204
8206
// fcmp ogt floor(x), x => false
8205
- // fcmp ogt x, ceil(x) => false
8206
- if (floor_x || x_ceil)
8207
+ if (floor_x)
8207
8208
return CI.replaceInstUsesWith (I, ConstantInt::getFalse (I.getType ()));
8208
8209
break ;
8209
8210
case FCmpInst::FCMP_OGE:
8210
- // fcmp oge x, floor(x) => fcmp ord x, 0
8211
8211
// fcmp oge ceil(x), x => fcmp ord x, 0
8212
- if (x_floor)
8213
- return new FCmpInst (FCmpInst::FCMP_ORD, LHS, ConstantFP::getZero (OpType),
8214
- " " , &I);
8215
8212
if (ceil_x)
8216
8213
return new FCmpInst (FCmpInst::FCMP_ORD, RHS, ConstantFP::getZero (OpType),
8217
8214
" " , &I);
8218
8215
break ;
8219
8216
case FCmpInst::FCMP_OLT:
8220
- // fcmp olt x, floor(x) => false
8221
8217
// fcmp olt ceil(x), x => false
8222
- if (x_floor || ceil_x)
8218
+ if (ceil_x)
8223
8219
return CI.replaceInstUsesWith (I, ConstantInt::getFalse (I.getType ()));
8224
8220
break ;
8225
8221
case FCmpInst::FCMP_ULE:
8226
8222
// fcmp ule floor(x), x => fcmp ule -inf, x
8227
- // fcmp ule x, ceil(x) => fcmp ule x, inf
8228
8223
if (floor_x)
8229
8224
return new FCmpInst (FCmpInst::FCMP_ULE,
8230
8225
ConstantFP::getInfinity (RHS->getType (), true ), RHS,
8231
8226
" " , &I);
8232
- if (x_ceil)
8233
- return new FCmpInst (FCmpInst::FCMP_ULE, LHS,
8234
- ConstantFP::getInfinity (LHS->getType (), false ), " " ,
8235
- &I);
8236
8227
break ;
8237
8228
case FCmpInst::FCMP_UGT:
8238
8229
// fcmp ugt floor(x), x => fcmp ugt -inf, x
8239
- // fcmp ugt x, ceil(x) => fcmp ugt x, inf
8240
8230
if (floor_x)
8241
8231
return new FCmpInst (FCmpInst::FCMP_UGT,
8242
8232
ConstantFP::getInfinity (RHS->getType (), true ), RHS,
8243
8233
" " , &I);
8244
- if (x_ceil)
8245
- return new FCmpInst (FCmpInst::FCMP_UGT, LHS,
8246
- ConstantFP::getInfinity (LHS->getType (), false ), " " ,
8247
- &I);
8248
8234
break ;
8249
8235
case FCmpInst::FCMP_UGE:
8250
- // fcmp uge x, floor(x) => fcmp uge x, -inf
8251
8236
// fcmp uge ceil(x), x => fcmp uge inf, x
8252
- if (x_floor)
8253
- return new FCmpInst (FCmpInst::FCMP_UGE, LHS,
8254
- ConstantFP::getInfinity (LHS->getType (), true ), " " ,
8255
- &I);
8256
8237
if (ceil_x)
8257
8238
return new FCmpInst (FCmpInst::FCMP_UGE,
8258
8239
ConstantFP::getInfinity (RHS->getType (), false ), RHS,
8259
8240
" " , &I);
8260
8241
break ;
8261
8242
case FCmpInst::FCMP_ULT:
8262
- // fcmp ult x, floor(x) => fcmp ult x, -inf
8263
8243
// fcmp ult ceil(x), x => fcmp ult inf, x
8264
- if (x_floor)
8265
- return new FCmpInst (FCmpInst::FCMP_ULT, LHS,
8266
- ConstantFP::getInfinity (LHS->getType (), true ), " " ,
8267
- &I);
8268
8244
if (ceil_x)
8269
8245
return new FCmpInst (FCmpInst::FCMP_ULT,
8270
8246
ConstantFP::getInfinity (RHS->getType (), false ), RHS,
0 commit comments