[llvm-commits] [llvm] r85085 - in /llvm/trunk: lib/Transforms/Scalar/InstructionCombining.cpp test/Transforms/InstCombine/or.ll test/Transforms/InstCombine/xor-demorgans.ll
Chris Lattner
sabre at nondot.org
Sun Oct 25 21:38:49 PDT 2009
thanks!
On Oct 25, 2009, at 8:40 PM, Evan Cheng wrote:
> Chris, this is causing an infinite looping during llvm-gcc build.
> I'll revert it.
>
> Evan
>
> On Oct 25, 2009, at 6:06 PM, Chris Lattner wrote:
>
>> Author: lattner
>> Date: Sun Oct 25 20:06:31 2009
>> New Revision: 85085
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=85085&view=rev
>> Log:
>> Implement PR3266 & PR5276, folding:
>> not (or (icmp, icmp)) -> and(icmp, icmp)
>>
>>
>> Removed:
>> llvm/trunk/test/Transforms/InstCombine/xor-demorgans.ll
>> Modified:
>> llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
>> llvm/trunk/test/Transforms/InstCombine/or.ll
>>
>> Modified: llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp?rev=85085&r1=85084&r2=85085&view=diff
>>
>> =
>> =
>> =
>> =
>> =
>> =
>> =
>> =
>> =
>> =====================================================================
>> --- llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
>> (original)
>> +++ llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp Sun
>> Oct 25 20:06:31 2009
>> @@ -631,9 +631,32 @@
>> return 0;
>> }
>>
>> -static inline Value *dyn_castNotVal(Value *V) {
>> +/// isFreeToInvert - Return true if the specified value is free to
>> invert (apply
>> +/// ~ to). This happens in cases where the ~ can be eliminated.
>> +static inline bool isFreeToInvert(Value *V) {
>> + // ~(~(X)) -> X.
>> if (BinaryOperator::isNot(V))
>> - return BinaryOperator::getNotArgument(V);
>> + return true;
>> +
>> + // Constants can be considered to be not'ed values.
>> + if (isa<ConstantInt>(V))
>> + return true;
>> +
>> + // Compares can be inverted if they have a single use.
>> + if (CmpInst *CI = dyn_cast<CmpInst>(V))
>> + return CI->hasOneUse();
>> +
>> + return false;
>> +}
>> +
>> +static inline Value *dyn_castNotVal(Value *V) {
>> + // If this is not(not(x)) don't return that this is a not: we
>> want the two
>> + // not's to be folded first.
>> + if (BinaryOperator::isNot(V)) {
>> + Value *Operand = BinaryOperator::getNotArgument(V);
>> + if (!isFreeToInvert(Operand))
>> + return Operand;
>> + }
>>
>> // Constants can be considered to be not'ed values...
>> if (ConstantInt *C = dyn_cast<ConstantInt>(V))
>> @@ -641,6 +664,8 @@
>> return 0;
>> }
>>
>> +
>> +
>> // dyn_castFoldableMul - If this value is a multiply that can be
>> folded into
>> // other computations (because it has a constant operand), return the
>> // non-constant operand of the multiply, and set CST to point to
>> the multiplier.
>> @@ -4166,7 +4191,7 @@
>> if (Instruction *CastOp = dyn_cast<Instruction>(CI->getOperand
>> (0))) {
>> if ((isa<TruncInst>(CI) || isa<BitCastInst>(CI)) &&
>> CastOp->getNumOperands() == 2)
>> - if (ConstantInt *AndCI = dyn_cast<ConstantInt>(CastOp-
>> >getOperand(1))) {
>> + if (ConstantInt *AndCI =dyn_cast<ConstantInt>(CastOp-
>> >getOperand(1))){
>> if (CastOp->getOpcode() == Instruction::And) {
>> // Change: and (cast (and X, C1) to T), C2
>> // into : and (cast X to T), trunc_or_bitcast(C1)&C2
>> @@ -5064,12 +5089,13 @@
>>
>> // Is this a ~ operation?
>> if (Value *NotOp = dyn_castNotVal(&I)) {
>> - // ~(~X & Y) --> (X | ~Y) - De Morgan's Law
>> - // ~(~X | Y) === (X & ~Y) - De Morgan's Law
>> if (BinaryOperator *Op0I = dyn_cast<BinaryOperator>(NotOp)) {
>> if (Op0I->getOpcode() == Instruction::And ||
>> Op0I->getOpcode() == Instruction::Or) {
>> - if (dyn_castNotVal(Op0I->getOperand(1))) Op0I->swapOperands
>> ();
>> + // ~(~X & Y) --> (X | ~Y) - De Morgan's Law
>> + // ~(~X | Y) === (X & ~Y) - De Morgan's Law
>> + if (dyn_castNotVal(Op0I->getOperand(1)))
>> + Op0I->swapOperands();
>> if (Value *Op0NotVal = dyn_castNotVal(Op0I->getOperand(0))) {
>> Value *NotY =
>> Builder->CreateNot(Op0I->getOperand(1),
>> @@ -5078,6 +5104,19 @@
>> return BinaryOperator::CreateOr(Op0NotVal, NotY);
>> return BinaryOperator::CreateAnd(Op0NotVal, NotY);
>> }
>> +
>> + // ~(X & Y) --> (~X | ~Y) - De Morgan's Law
>> + // ~(X | Y) === (~X & ~Y) - De Morgan's Law
>> + if (isFreeToInvert(Op0I->getOperand(0)) &&
>> + isFreeToInvert(Op0I->getOperand(1))) {
>> + Value *NotX =
>> + Builder->CreateNot(Op0I->getOperand(0), "notlhs");
>> + Value *NotY =
>> + Builder->CreateNot(Op0I->getOperand(1), "notrhs");
>> + if (Op0I->getOpcode() == Instruction::And)
>> + return BinaryOperator::CreateOr(NotX, NotY);
>> + return BinaryOperator::CreateAnd(NotX, NotY);
>> + }
>> }
>> }
>> }
>>
>> Modified: llvm/trunk/test/Transforms/InstCombine/or.ll
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/or.ll?rev=85085&r1=85084&r2=85085&view=diff
>>
>> =
>> =
>> =
>> =
>> =
>> =
>> =
>> =
>> =
>> =====================================================================
>> --- llvm/trunk/test/Transforms/InstCombine/or.ll (original)
>> +++ llvm/trunk/test/Transforms/InstCombine/or.ll Sun Oct 25
>> 20:06:31 2009
>> @@ -237,4 +237,19 @@
>> ; CHECK: @test24
>> ; CHECK: %bothcond = fcmp uno double %Y, %X ; <i1>
>> [#uses=1]
>> ; CHECK: ret i1 %bothcond
>> -}
>> \ No newline at end of file
>> +}
>> +
>> +; PR3266 & PR5276
>> +define i1 @test25(i32 %A, i32 %B) {
>> + %C = icmp eq i32 %A, 0
>> + %D = icmp eq i32 %B, 57
>> + %E = or i1 %C, %D
>> + %F = xor i1 %E, -1
>> + ret i1 %F
>> +
>> +; CHECK: @test25
>> +; CHECK: icmp ne i32 %A, 0
>> +; CHECK-NEXT: icmp ne i32 %B, 57
>> +; CHECK-NEXT: %F = and i1
>> +; CHECK-NEXT: ret i1 %F
>> +}
>>
>> Removed: llvm/trunk/test/Transforms/InstCombine/xor-demorgans.ll
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/xor-demorgans.ll?rev=85084&view=auto
>>
>> =
>> =
>> =
>> =
>> =
>> =
>> =
>> =
>> =
>> =====================================================================
>> --- llvm/trunk/test/Transforms/InstCombine/xor-demorgans.ll
>> (original)
>> +++ llvm/trunk/test/Transforms/InstCombine/xor-demorgans.ll (removed)
>> @@ -1,12 +0,0 @@
>> -; RUN: opt < %s -instcombine -S | not grep {= or}
>> -; PR3266
>> -; XFAIL: *
>> -
>> -define i1 @foo(i32 %x, i32 %y) nounwind {
>> -.summary:
>> - %0 = icmp sgt i32 %x, 4 ; <i1> [#uses=1]
>> - %1 = icmp sgt i32 %y, 0 ; <i1> [#uses=1]
>> - %.demorgan = or i1 %1, %0 ; <i1> [#uses=1]
>> - %2 = xor i1 %.demorgan, true ; <i1> [#uses=1]
>> - ret i1 %2
>> -}
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list