[PATCH] [BUG] Fix regression in the instruction combiner after r214385

Zinovy Nis zinovy.nis at gmail.com
Mon Aug 25 00:15:17 PDT 2014


David, thank for your commit. But why we need to replace SUB with ADD in LLVM IR? I see no reasons for it? Or may be there's a pass which strictly needs namely ADD and fail to deal with SUB? If not, I'd prefer patch from my first comment:


```
// If this is a 'B = x-(-A)', change to B = x+A.
  if (const auto *BO = dyn_cast<BinaryOperator>(Op1)) {
    if (Value *V = dyn_castNegVal(Op1)) {
      BinaryOperator *Res = BinaryOperator::CreateAdd(Op0, V);
      assert(BO->getOpcode() == Instruction::Sub &&
             "Expected a subtraction operator!");
      if (BO->hasNoSignedWrap() && I.hasNoSignedWrap())
        Res->setHasNoSignedWrap(true);
      return Res;
    }
  }
```

http://reviews.llvm.org/D5007






More information about the llvm-commits mailing list