llvm.org GIT mirror llvm / 8205283
Teach ScalarEvolution how to recognize another xor(and(x, C), C) case. If C is a single bit and the and gets analyzed as a truncate and zero-extend, the xor can be represnted as an add. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@73664 91177308-0d34-0410-b5e6-96231b3b80d8 Dan Gohman 11 years ago
2 changed file(s) with 22 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
24522452 LCI->getValue() == CI->getValue())
24532453 if (const SCEVZeroExtendExpr *Z =
24542454 dyn_cast(getSCEV(U->getOperand(0)))) {
2455 SCEVHandle ZO = Z->getOperand();
2456 if (APIntOps::isMask(getTypeSizeInBits(ZO->getType()),
2457 CI->getValue()))
2458 return getZeroExtendExpr(getNotSCEV(ZO), U->getType());
2455 const Type *UTy = U->getType();
2456 SCEVHandle Z0 = Z->getOperand();
2457 const Type *Z0Ty = Z0->getType();
2458 unsigned Z0TySize = getTypeSizeInBits(Z0Ty);
2459
2460 // If C is a low-bits mask, the zero extend is zerving to
2461 // mask off the high bits. Complement the operand and
2462 // re-apply the zext.
2463 if (APIntOps::isMask(Z0TySize, CI->getValue()))
2464 return getZeroExtendExpr(getNotSCEV(Z0), UTy);
2465
2466 // If C is a single bit, it may be in the sign-bit position
2467 // before the zero-extend. In this case, represent the xor
2468 // using an add, which is equivalent, and re-apply the zext.
2469 APInt Trunc = APInt(CI->getValue()).trunc(Z0TySize);
2470 if (APInt(Trunc).zext(getTypeSizeInBits(UTy)) == CI->getValue() &&
2471 Trunc.isSignBit())
2472 return getZeroExtendExpr(getAddExpr(Z0, getConstant(Trunc)),
2473 UTy);
24592474 }
24602475 }
24612476 break;
None ; RUN: llvm-as < %s | opt -scalar-evolution -disable-output -analyze | grep {\\--> %z}
0 ; RUN: llvm-as < %s | opt -scalar-evolution -disable-output -analyze \
1 ; RUN: | grep {\\--> (zext i4 (-8 + (trunc i64 (8 \\* %x) to i4)) to i64)}
12
2 ; ScalarEvolution shouldn't try to analyze %s into something like
3 ; ScalarEvolution shouldn't try to analyze %z into something like
34 ; --> (zext i4 (-1 + (-1 * (trunc i64 (8 * %x) to i4))) to i64)
45
56 define i64 @foo(i64 %x) {