diff options
| author | Shuxin Yang <shuxin.llvm@gmail.com> | 2013-04-27 18:02:12 +0000 | 
|---|---|---|
| committer | Shuxin Yang <shuxin.llvm@gmail.com> | 2013-04-27 18:02:12 +0000 | 
| commit | 04a4fd43aa9ef807b54a42f3a0aa1234ce579dda (patch) | |
| tree | 05bd85d87ae4d0967c8e0f2906cc349eaa5830a2 /llvm/lib | |
| parent | 7d8b607f4693a94e85c12429a832e53923680349 (diff) | |
| download | bcm5719-llvm-04a4fd43aa9ef807b54a42f3a0aa1234ce579dda.tar.gz bcm5719-llvm-04a4fd43aa9ef807b54a42f3a0aa1234ce579dda.zip | |
Fix a XOR reassociation bug. 
When Reassociator optimize "(x | C1)" ^ "(X & C2)", it may swap the two
subexpressions, however, it forgot to swap cached constants (of C1 and C2)
accordingly.
rdar://13739160
llvm-svn: 180676
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/Reassociate.cpp | 9 | 
1 files changed, 6 insertions, 3 deletions
| diff --git a/llvm/lib/Transforms/Scalar/Reassociate.cpp b/llvm/lib/Transforms/Scalar/Reassociate.cpp index fc3b38ee53b..a3c241dc0f2 100644 --- a/llvm/lib/Transforms/Scalar/Reassociate.cpp +++ b/llvm/lib/Transforms/Scalar/Reassociate.cpp @@ -1195,9 +1195,6 @@ bool Reassociate::CombineXorOpnd(Instruction *I, XorOpnd *Opnd1, XorOpnd *Opnd2,    if (X != Opnd2->getSymbolicPart())      return false; -  const APInt &C1 = Opnd1->getConstPart(); -  const APInt &C2 = Opnd2->getConstPart(); -    // This many instruction become dead.(At least "Opnd1 ^ Opnd2" will die.)    int DeadInstNum = 1;    if (Opnd1->getValue()->hasOneUse()) @@ -1215,6 +1212,8 @@ bool Reassociate::CombineXorOpnd(Instruction *I, XorOpnd *Opnd1, XorOpnd *Opnd2,      if (Opnd2->isOrExpr())        std::swap(Opnd1, Opnd2); +    const APInt &C1 = Opnd1->getConstPart(); +    const APInt &C2 = Opnd2->getConstPart();      APInt C3((~C1) ^ C2);      // Do not increase code size! @@ -1230,6 +1229,8 @@ bool Reassociate::CombineXorOpnd(Instruction *I, XorOpnd *Opnd1, XorOpnd *Opnd2,    } else if (Opnd1->isOrExpr()) {      // Xor-Rule 3: (x | c1) ^ (x | c2) = (x & c3) ^ c3 where c3 = c1 ^ c2      // +    const APInt &C1 = Opnd1->getConstPart(); +    const APInt &C2 = Opnd2->getConstPart();      APInt C3 = C1 ^ C2;      // Do not increase code size @@ -1244,6 +1245,8 @@ bool Reassociate::CombineXorOpnd(Instruction *I, XorOpnd *Opnd1, XorOpnd *Opnd2,    } else {      // Xor-Rule 4: (x & c1) ^ (x & c2) = (x & (c1^c2))      // +    const APInt &C1 = Opnd1->getConstPart(); +    const APInt &C2 = Opnd2->getConstPart();      APInt C3 = C1 ^ C2;      Res = createAndInstr(I, X, C3);    } | 

