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

Zinovy Nis zinovy.nis at gmail.com
Fri Aug 22 02:56:05 PDT 2014


If SUB to ADD transformation is not required, my patch can be simplified to 


```
  // 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;
      }
    }
```

David, how do you think?

http://reviews.llvm.org/D5007






More information about the llvm-commits mailing list