[PATCH] D31398: [X86][X86 intrinsics]Folding cmp(sub(a, b), 0) into cmp(a, b) optimization
Sanjay Patel via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 14 07:26:33 PDT 2017
spatel added inline comments.
================
Comment at: Transforms/InstCombine/InstCombineCalls.cpp:2348-2366
+ for (int i = 0; i < 2; i++) {
+ // Folding cmp(sub(a,b),0) into cmp(a,b)
+ if (auto *I = dyn_cast<Instruction>(II->getArgOperand(i))) {
+ if (I->getOpcode() == Instruction::FSub && I->hasOneUse()) {
+ // This fold requires only the NINF(not +/- inf) since inf minus
+ // inf is nan.
+ // NSZ(No Signed Zeros) is not needed because zeros of any sign are
----------------
There are many ways to deal with commuted patterns, and a 2-loop is my least favorite. Would you consider using std::swap and matchers instead? Something like:
Value *Arg0 = II->getArgOperand(0);
Value *Arg1 = II->getArgOperand(1);
bool Arg0IsZero = match(Arg0, m_Zero());
if (Arg0IsZero)
std::swap(Arg0, Arg1);
Value *A, *B;
if ((match(Arg0, m_OneUse(m_FSub(m_Value(A), m_Value(B)))) &&
match(Arg1, m_Zero()) &&
cast<Instruction>(Arg0)->getFastMathFlags().noInfs())) {
if (Arg0IsZero)
std::swap(A, B);
II->setArgOperand(0, A);
II->setArgOperand(1, B);
return II;
}
https://reviews.llvm.org/D31398
More information about the llvm-commits
mailing list