Skip to content

Commit 34a8e5b

Browse files
committed
swap operand
1 parent 1f1a8f8 commit 34a8e5b

File tree

1 file changed

+9
-33
lines changed

1 file changed

+9
-33
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8182,89 +8182,65 @@ static Instruction *foldFCmpWithFloorAndCeil(FCmpInst &I,
81828182
InstCombinerImpl &CI) {
81838183
Value *LHS = I.getOperand(0), *RHS = I.getOperand(1);
81848184
Type *OpType = LHS->getType();
8185-
const CmpInst::Predicate Pred = I.getPredicate();
8185+
CmpInst::Predicate Pred = I.getPredicate();
81868186

81878187
bool floor_x = match(LHS, m_Intrinsic<Intrinsic::floor>(m_Specific(RHS)));
81888188
bool x_floor = match(RHS, m_Intrinsic<Intrinsic::floor>(m_Specific(LHS)));
81898189
bool ceil_x = match(LHS, m_Intrinsic<Intrinsic::ceil>(m_Specific(RHS)));
81908190
bool x_ceil = match(RHS, m_Intrinsic<Intrinsic::ceil>(m_Specific(LHS)));
81918191

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+
81928198
switch (Pred) {
81938199
case FCmpInst::FCMP_OLE:
81948200
// fcmp ole floor(x), x => fcmp ord x, 0
8195-
// fcmp ole x, ceil(x) => fcmp ord x, 0
81968201
if (floor_x)
81978202
return new FCmpInst(FCmpInst::FCMP_ORD, RHS, ConstantFP::getZero(OpType),
81988203
"", &I);
8199-
if (x_ceil)
8200-
return new FCmpInst(FCmpInst::FCMP_ORD, LHS, ConstantFP::getZero(OpType),
8201-
"", &I);
82028204
break;
82038205
case FCmpInst::FCMP_OGT:
82048206
// fcmp ogt floor(x), x => false
8205-
// fcmp ogt x, ceil(x) => false
8206-
if (floor_x || x_ceil)
8207+
if (floor_x)
82078208
return CI.replaceInstUsesWith(I, ConstantInt::getFalse(I.getType()));
82088209
break;
82098210
case FCmpInst::FCMP_OGE:
8210-
// fcmp oge x, floor(x) => fcmp ord x, 0
82118211
// 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);
82158212
if (ceil_x)
82168213
return new FCmpInst(FCmpInst::FCMP_ORD, RHS, ConstantFP::getZero(OpType),
82178214
"", &I);
82188215
break;
82198216
case FCmpInst::FCMP_OLT:
8220-
// fcmp olt x, floor(x) => false
82218217
// fcmp olt ceil(x), x => false
8222-
if (x_floor || ceil_x)
8218+
if (ceil_x)
82238219
return CI.replaceInstUsesWith(I, ConstantInt::getFalse(I.getType()));
82248220
break;
82258221
case FCmpInst::FCMP_ULE:
82268222
// fcmp ule floor(x), x => fcmp ule -inf, x
8227-
// fcmp ule x, ceil(x) => fcmp ule x, inf
82288223
if (floor_x)
82298224
return new FCmpInst(FCmpInst::FCMP_ULE,
82308225
ConstantFP::getInfinity(RHS->getType(), true), RHS,
82318226
"", &I);
8232-
if (x_ceil)
8233-
return new FCmpInst(FCmpInst::FCMP_ULE, LHS,
8234-
ConstantFP::getInfinity(LHS->getType(), false), "",
8235-
&I);
82368227
break;
82378228
case FCmpInst::FCMP_UGT:
82388229
// fcmp ugt floor(x), x => fcmp ugt -inf, x
8239-
// fcmp ugt x, ceil(x) => fcmp ugt x, inf
82408230
if (floor_x)
82418231
return new FCmpInst(FCmpInst::FCMP_UGT,
82428232
ConstantFP::getInfinity(RHS->getType(), true), RHS,
82438233
"", &I);
8244-
if (x_ceil)
8245-
return new FCmpInst(FCmpInst::FCMP_UGT, LHS,
8246-
ConstantFP::getInfinity(LHS->getType(), false), "",
8247-
&I);
82488234
break;
82498235
case FCmpInst::FCMP_UGE:
8250-
// fcmp uge x, floor(x) => fcmp uge x, -inf
82518236
// 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);
82568237
if (ceil_x)
82578238
return new FCmpInst(FCmpInst::FCMP_UGE,
82588239
ConstantFP::getInfinity(RHS->getType(), false), RHS,
82598240
"", &I);
82608241
break;
82618242
case FCmpInst::FCMP_ULT:
8262-
// fcmp ult x, floor(x) => fcmp ult x, -inf
82638243
// 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);
82688244
if (ceil_x)
82698245
return new FCmpInst(FCmpInst::FCMP_ULT,
82708246
ConstantFP::getInfinity(RHS->getType(), false), RHS,

0 commit comments

Comments
 (0)