[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-06-21 Thread Chris Lattner


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.774 - 1.775
---
Log message:

Significantly improve the documentation of the instcombine divide/compare 
transformation.  Also, keep track of which end of the integer interval overflows
occur on.  This fixes Transforms/InstCombine/2007-06-21-DivCompareMiscomp.ll
and rdar://5278853, a miscompilation of perl.



---
Diffs of the changes:  (+50 -34)

 InstructionCombining.cpp |   84 +++
 1 files changed, 50 insertions(+), 34 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.774 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.775
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.774   Wed Jun 20 
18:46:26 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Thu Jun 21 13:11:19 2007
@@ -5131,12 +5131,7 @@
   if (!ICI.isEquality()  DivIsSigned != ICI.isSignedPredicate())
 return 0;
   if (DivRHS-isZero())
-return 0; // Don't hack on div by zero
-
-  // Initialize the variables that will indicate the nature of the
-  // range check.
-  bool LoOverflow = false, HiOverflow = false;
-  ConstantInt *LoBound = 0, *HiBound = 0;
+return 0; // The ProdOV computation fails on divide by zero.
 
   // Compute Prod = CI * DivRHS. We are essentially solving an equation
   // of form X/C1=C2. We solve for X by multiplying C1 (DivRHS) and 
@@ -5151,87 +5146,108 @@
  ConstantExpr::getUDiv(Prod, DivRHS)) != CmpRHS;
 
   // Get the ICmp opcode
-  ICmpInst::Predicate predicate = ICI.getPredicate();
+  ICmpInst::Predicate Pred = ICI.getPredicate();
 
+  // Figure out the interval that is being checked.  For example, a comparison
+  // like X /u 5 == 0 is really checking that X is in the interval [0, 5). 
+  // Compute this interval based on the constants involved and the signedness 
of
+  // the compare/divide.  This computes a half-open interval, keeping track of
+  // whether either value in the interval overflows.  After analysis each
+  // overflow variable is set to 0 if it's corresponding bound variable is 
valid
+  // -1 if overflowed off the bottom end, or +1 if overflowed off the top end.
+  int LoOverflow = 0, HiOverflow = 0;
+  ConstantInt *LoBound = 0, *HiBound = 0;
+  
+  
   if (!DivIsSigned) {  // udiv
+// e.g. X/5 op 3  -- [15, 20)
 LoBound = Prod;
-LoOverflow = ProdOV;
-HiOverflow = ProdOV || AddWithOverflow(HiBound, LoBound, DivRHS, false);
+HiOverflow = LoOverflow = ProdOV;
+if (!HiOverflow)
+  HiOverflow = AddWithOverflow(HiBound, LoBound, DivRHS, false);
   } else if (DivRHS-getValue().isPositive()) { // Divisor is  0.
 if (CmpRHSV == 0) {   // (X / pos) op 0
-  // Can't overflow.
+  // Can't overflow.  e.g.  X/2 op 0 -- [-1, 2)
   LoBound = castConstantInt(ConstantExpr::getNeg(SubOne(DivRHS)));
   HiBound = DivRHS;
 } else if (CmpRHSV.isPositive()) {   // (X / pos) op pos
-  LoBound = Prod;
-  LoOverflow = ProdOV;
-  HiOverflow = ProdOV || AddWithOverflow(HiBound, Prod, DivRHS, true);
+  LoBound = Prod; // e.g.   X/5 op 3 -- [15, 20)
+  HiOverflow = LoOverflow = ProdOV;
+  if (!HiOverflow)
+HiOverflow = AddWithOverflow(HiBound, Prod, DivRHS, true);
 } else {   // (X / pos) op neg
+  // e.g. X/5 op -3  -- [-15-4, -15+1) -- [-19, -14)
   Constant *DivRHSH = ConstantExpr::getNeg(SubOne(DivRHS));
   LoOverflow = AddWithOverflow(LoBound, Prod,
-   castConstantInt(DivRHSH), true);
+   castConstantInt(DivRHSH), true) ? -1 : 0;
   HiBound = AddOne(Prod);
-  HiOverflow = ProdOV;
+  HiOverflow = ProdOV ? -1 : 0;
 }
   } else { // Divisor is  0.
 if (CmpRHSV == 0) {   // (X / neg) op 0
+  // e.g. X/-5 op 0  -- [-4, 5)
   LoBound = AddOne(DivRHS);
   HiBound = castConstantInt(ConstantExpr::getNeg(DivRHS));
-  if (HiBound == DivRHS)
-return 0;   // - INTMIN = INTMIN
+  if (HiBound == DivRHS) { // -INTMIN = INTMIN
+HiOverflow = 1;// [INTMIN+1, overflow)
+HiBound = 0;   // e.g. X/INTMIN = 0 -- X  INTMIN
+  }
 } else if (CmpRHSV.isPositive()) {   // (X / neg) op pos
-  HiOverflow = LoOverflow = ProdOV;
+  // e.g. X/-5 op 3  -- [-19, -14)
+  HiOverflow = LoOverflow = ProdOV ? -1 : 0;
   if (!LoOverflow)
-LoOverflow = AddWithOverflow(LoBound, Prod, AddOne(DivRHS),
- true);
+LoOverflow = AddWithOverflow(LoBound, Prod, AddOne(DivRHS), true) 
?-1:0;
   HiBound = AddOne(Prod);
 } else {   // (X / neg) op neg
+  // e.g. X/-5 op -3  -- [15, 20)
   LoBound = Prod;
-  LoOverflow = HiOverflow = ProdOV;
+  LoOverflow = HiOverflow = ProdOV 

[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-06-20 Thread Chris Lattner


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.773 - 1.774
---
Log message:

refactor a bunch of code out of visitICmpInstWithInstAndIntCst into its own
routine.


---
Diffs of the changes:  (+134 -123)

 InstructionCombining.cpp |  257 ---
 1 files changed, 134 insertions(+), 123 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.773 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.774
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.773   Tue Jun 19 
00:43:49 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Wed Jun 20 18:46:26 2007
@@ -189,6 +189,8 @@
 Instruction *visitICmpInstWithInstAndIntCst(ICmpInst ICI,
 Instruction *LHS,
 ConstantInt *RHS);
+Instruction *FoldICmpDivCst(ICmpInst ICI, BinaryOperator *DivI,
+ConstantInt *DivRHS);
 
 Instruction *FoldGEPICmp(User *GEPLHS, Value *RHS,
  ICmpInst::Predicate Cond, Instruction I);
@@ -5109,6 +5111,134 @@
   return Changed ? I : 0;
 }
 
+
+/// FoldICmpDivCst - Fold icmp pred, ([su]div X, DivRHS), CmpRHS where DivRHS
+/// and CmpRHS are both known to be integer constants.
+Instruction *InstCombiner::FoldICmpDivCst(ICmpInst ICI, BinaryOperator *DivI,
+  ConstantInt *DivRHS) {
+  ConstantInt *CmpRHS = castConstantInt(ICI.getOperand(1));
+  const APInt CmpRHSV = CmpRHS-getValue();
+  
+  // FIXME: If the operand types don't match the type of the divide 
+  // then don't attempt this transform. The code below doesn't have the
+  // logic to deal with a signed divide and an unsigned compare (and
+  // vice versa). This is because (x /s C1) s C2  produces different 
+  // results than (x /s C1) u C2 or (x /u C1) s C2 or even
+  // (x /u C1) u C2.  Simply casting the operands and result won't 
+  // work. :(  The if statement below tests that condition and bails 
+  // if it finds it. 
+  bool DivIsSigned = DivI-getOpcode() == Instruction::SDiv;
+  if (!ICI.isEquality()  DivIsSigned != ICI.isSignedPredicate())
+return 0;
+  if (DivRHS-isZero())
+return 0; // Don't hack on div by zero
+
+  // Initialize the variables that will indicate the nature of the
+  // range check.
+  bool LoOverflow = false, HiOverflow = false;
+  ConstantInt *LoBound = 0, *HiBound = 0;
+
+  // Compute Prod = CI * DivRHS. We are essentially solving an equation
+  // of form X/C1=C2. We solve for X by multiplying C1 (DivRHS) and 
+  // C2 (CI). By solving for X we can turn this into a range check 
+  // instead of computing a divide. 
+  ConstantInt *Prod = Multiply(CmpRHS, DivRHS);
+
+  // Determine if the product overflows by seeing if the product is
+  // not equal to the divide. Make sure we do the same kind of divide
+  // as in the LHS instruction that we're folding. 
+  bool ProdOV = (DivIsSigned ? ConstantExpr::getSDiv(Prod, DivRHS) :
+ ConstantExpr::getUDiv(Prod, DivRHS)) != CmpRHS;
+
+  // Get the ICmp opcode
+  ICmpInst::Predicate predicate = ICI.getPredicate();
+
+  if (!DivIsSigned) {  // udiv
+LoBound = Prod;
+LoOverflow = ProdOV;
+HiOverflow = ProdOV || AddWithOverflow(HiBound, LoBound, DivRHS, false);
+  } else if (DivRHS-getValue().isPositive()) { // Divisor is  0.
+if (CmpRHSV == 0) {   // (X / pos) op 0
+  // Can't overflow.
+  LoBound = castConstantInt(ConstantExpr::getNeg(SubOne(DivRHS)));
+  HiBound = DivRHS;
+} else if (CmpRHSV.isPositive()) {   // (X / pos) op pos
+  LoBound = Prod;
+  LoOverflow = ProdOV;
+  HiOverflow = ProdOV || AddWithOverflow(HiBound, Prod, DivRHS, true);
+} else {   // (X / pos) op neg
+  Constant *DivRHSH = ConstantExpr::getNeg(SubOne(DivRHS));
+  LoOverflow = AddWithOverflow(LoBound, Prod,
+   castConstantInt(DivRHSH), true);
+  HiBound = AddOne(Prod);
+  HiOverflow = ProdOV;
+}
+  } else { // Divisor is  0.
+if (CmpRHSV == 0) {   // (X / neg) op 0
+  LoBound = AddOne(DivRHS);
+  HiBound = castConstantInt(ConstantExpr::getNeg(DivRHS));
+  if (HiBound == DivRHS)
+return 0;   // - INTMIN = INTMIN
+} else if (CmpRHSV.isPositive()) {   // (X / neg) op pos
+  HiOverflow = LoOverflow = ProdOV;
+  if (!LoOverflow)
+LoOverflow = AddWithOverflow(LoBound, Prod, AddOne(DivRHS),
+ true);
+  HiBound = AddOne(Prod);
+} else {   // (X / neg) op neg
+  LoBound = Prod;
+  LoOverflow = HiOverflow = ProdOV;
+  HiBound = Subtract(Prod, DivRHS);
+}
+
+// Dividing by a negate swaps the condition.
+predicate = 

[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-06-18 Thread Chris Lattner


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.772 - 1.773
---
Log message:

silence a bogus warning Duraid ran into.



---
Diffs of the changes:  (+1 -1)

 InstructionCombining.cpp |2 +-
 1 files changed, 1 insertion(+), 1 deletion(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.772 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.773
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.772   Fri Jun 15 
01:23:19 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Tue Jun 19 00:43:49 2007
@@ -3808,7 +3808,7 @@
   }
 
   // (A  C)|(B  D)
-  Value *C, *D;
+  Value *C = 0, *D = 0;
   if (match(Op0, m_And(m_Value(A), m_Value(C))) 
   match(Op1, m_And(m_Value(B), m_Value(D {
 Value *V1 = 0, *V2 = 0, *V3 = 0;



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-06-14 Thread Chris Lattner


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.769 - 1.770
---
Log message:

delete some obviously dead vector operations, which deletes a few thousand
operations from Duraids example.


---
Diffs of the changes:  (+12 -1)

 InstructionCombining.cpp |   13 -
 1 files changed, 12 insertions(+), 1 deletion(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.769 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.770
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.769   Wed Jun  6 
12:08:48 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Fri Jun 15 00:26:55 2007
@@ -3245,8 +3245,10 @@
   return I;
   } else {
 if (ConstantVector *CP = dyn_castConstantVector(Op1)) {
-  if (CP-isAllOnesValue())
+  if (CP-isAllOnesValue())// X  -1,-1 - X
 return ReplaceInstUsesWith(I, I.getOperand(0));
+} else if (isaConstantAggregateZero(Op1)) {
+  return ReplaceInstUsesWith(I, Op1);  // X  0,0 - 0,0
 }
   }
   
@@ -3714,7 +3716,14 @@
 if (SimplifyDemandedBits(I, APInt::getAllOnesValue(BitWidth),
  KnownZero, KnownOne))
   return I;
+  } else if (isaConstantAggregateZero(Op1)) {
+return ReplaceInstUsesWith(I, Op0);  // X | 0,0 - X
+  } else if (ConstantVector *CP = dyn_castConstantVector(Op1)) {
+if (CP-isAllOnesValue())// X | -1,-1 - -1,-1
+  return ReplaceInstUsesWith(I, I.getOperand(1));
   }
+
+
   
   // or X, -1 == -1
   if (ConstantInt *RHS = dyn_castConstantInt(Op1)) {
@@ -4107,6 +4116,8 @@
 if (SimplifyDemandedBits(I, APInt::getAllOnesValue(BitWidth),
  KnownZero, KnownOne))
   return I;
+  } else if (isaConstantAggregateZero(Op1)) {
+return ReplaceInstUsesWith(I, Op0);  // X ^ 0,0 - X
   }
 
   if (ConstantInt *RHS = dyn_castConstantInt(Op1)) {



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-06-14 Thread Chris Lattner


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.770 - 1.771
---
Log message:

Implement two xforms:
1. ~(~X | Y) === (X  ~Y) 
2. (A|B)  ~(AB) - A^B

This allows us to transform  ~(~(a|b) | (ab)) - a^b.

This implements PR1510: http://llvm.org/PR1510  for scalar values.


---
Diffs of the changes:  (+26 -6)

 InstructionCombining.cpp |   32 ++--
 1 files changed, 26 insertions(+), 6 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.770 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.771
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.770   Fri Jun 15 
00:26:55 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Fri Jun 15 00:58:24 2007
@@ -3363,13 +3363,28 @@
   }
   
   {
-Value *A = 0, *B = 0;
-if (match(Op0, m_Or(m_Value(A), m_Value(B
+Value *A = 0, *B = 0, *C = 0, *D = 0;
+if (match(Op0, m_Or(m_Value(A), m_Value(B {
   if (A == Op1 || B == Op1)// (A | ?)  A  -- A
 return ReplaceInstUsesWith(I, Op1);
-if (match(Op1, m_Or(m_Value(A), m_Value(B
+
+  // (A|B)  ~(AB) - A^B
+  if (match(Op1, m_Not(m_And(m_Value(C), m_Value(D) {
+if ((A == C  B == D) || (A == D  B == C))
+  return BinaryOperator::createXor(A, B);
+  }
+}
+
+if (match(Op1, m_Or(m_Value(A), m_Value(B {
   if (A == Op0 || B == Op0)// A  (A | ?)  -- A
 return ReplaceInstUsesWith(I, Op0);
+
+  // ~(AB)  (A|B) - A^B
+  if (match(Op0, m_Not(m_And(m_Value(C), m_Value(D) {
+if ((A == C  B == D) || (A == D  B == C))
+  return BinaryOperator::createXor(A, B);
+  }
+}
 
 if (Op0-hasOneUse() 
 match(Op0, m_Xor(m_Value(A), m_Value(B {
@@ -4137,15 +4152,20 @@
   return BinaryOperator::createAdd(Op0I-getOperand(1), ConstantRHS);
 }
 
-  // ~(~X  Y) -- (X | ~Y)
-  if (Op0I-getOpcode() == Instruction::And  RHS-isAllOnesValue()) {
+  // ~(~X  Y) -- (X | ~Y) - De Morgan's Law
+  // ~(~X | Y) === (X  ~Y) - De Morgan's Law
+  if ((Op0I-getOpcode() == Instruction::And || 
+   Op0I-getOpcode() == Instruction::Or)  RHS-isAllOnesValue()) {
 if (dyn_castNotVal(Op0I-getOperand(1))) Op0I-swapOperands();
 if (Value *Op0NotVal = dyn_castNotVal(Op0I-getOperand(0))) {
   Instruction *NotY =
 BinaryOperator::createNot(Op0I-getOperand(1),
   Op0I-getOperand(1)-getName()+.not);
   InsertNewInstBefore(NotY, I);
-  return BinaryOperator::createOr(Op0NotVal, NotY);
+  if (Op0I-getOpcode() == Instruction::And)
+return BinaryOperator::createOr(Op0NotVal, NotY);
+  else
+return BinaryOperator::createAnd(Op0NotVal, NotY);
 }
   }
   



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-06-06 Thread Lauro Ramos Venancio


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.768 - 1.769
---
Log message:

Fix PR1499: http://llvm.org/PR1499 .



---
Diffs of the changes:  (+4 -0)

 InstructionCombining.cpp |4 
 1 files changed, 4 insertions(+)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.768 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.769
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.768   Tue May 22 
20:17:04 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Wed Jun  6 12:08:48 2007
@@ -1346,6 +1346,10 @@
   
   // Signed shift right.
   APInt DemandedMaskIn(DemandedMask.shl(ShiftAmt));
+  // If any of the high bits are demanded, we should set the sign bit as
+  // demanded.
+  if (DemandedMask.countLeadingZeros() = ShiftAmt)
+DemandedMaskIn.set(BitWidth-1);
   if (SimplifyDemandedBits(I-getOperand(0),
DemandedMaskIn,
RHSKnownZero, RHSKnownOne, Depth+1))



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


Re: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-06-06 Thread Chris Lattner

 Fix PR1499: http://llvm.org/PR1499 .

Very nice, thanks again Lauro!

-Chris


 ---
 Diffs of the changes:  (+4 -0)

  InstructionCombining.cpp |4 
  1 files changed, 4 insertions(+)


 Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
 diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.768  
 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.769
 --- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.768 Tue  
 May 22 20:17:04 2007
 +++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp   Wed Jun  6  
 12:08:48 2007
 @@ -1346,6 +1346,10 @@

// Signed shift right.
APInt DemandedMaskIn(DemandedMask.shl(ShiftAmt));
 +  // If any of the high bits are demanded, we should set the  
 sign bit as
 +  // demanded.
 +  if (DemandedMask.countLeadingZeros() = ShiftAmt)
 +DemandedMaskIn.set(BitWidth-1);
if (SimplifyDemandedBits(I-getOperand(0),
 DemandedMaskIn,
 RHSKnownZero, RHSKnownOne, Depth+1))



 ___
 llvm-commits mailing list
 llvm-commits@cs.uiuc.edu
 http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits

___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-05-22 Thread Chris Lattner


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.767 - 1.768
---
Log message:

fix a miscompilation when passing a float through varargs


---
Diffs of the changes:  (+1 -2)

 InstructionCombining.cpp |3 +--
 1 files changed, 1 insertion(+), 2 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.767 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.768
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.767   Sat May 19 
01:51:32 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Tue May 22 20:17:04 2007
@@ -389,8 +389,7 @@
   if (const IntegerType* ITy = dyn_castIntegerType(Ty)) {
 if (ITy-getBitWidth()  32)
   return Type::Int32Ty;
-  } else if (Ty == Type::FloatTy)
-return Type::DoubleTy;
+  }
   return Ty;
 }
 



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-05-19 Thread Chris Lattner


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.766 - 1.767
---
Log message:

Fix Transforms/InstCombine/2007-05-18-CastFoldBug.ll, a bug that devastates
objc code due to the way the FE lowers objc message sends.


---
Diffs of the changes:  (+8 -0)

 InstructionCombining.cpp |8 
 1 files changed, 8 insertions(+)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.766 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.767
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.766   Mon May 14 
19:16:00 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Sat May 19 01:51:32 2007
@@ -7773,6 +7773,14 @@
   const FunctionType *FT = Callee-getFunctionType();
   const Type *OldRetTy = Caller-getType();
 
+  const FunctionType *ActualFT =
+castFunctionType(castPointerType(CE-getType())-getElementType());
+  
+  // If the parameter attributes don't match up, don't do the xform.  We don't
+  // want to lose an sret attribute or something.
+  if (FT-getParamAttrs() != ActualFT-getParamAttrs())
+return false;
+  
   // Check to see if we are changing the return type...
   if (OldRetTy != FT-getReturnType()) {
 if (Callee-isDeclaration()  !Caller-use_empty()  



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-05-14 Thread Chris Lattner


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.765 - 1.766
---
Log message:

Fix Transforms/InstCombine/2007-05-14-Crash.ll


---
Diffs of the changes:  (+16 -7)

 InstructionCombining.cpp |   23 ---
 1 files changed, 16 insertions(+), 7 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.765 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.766
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.765   Fri May 11 
16:10:54 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Mon May 14 19:16:00 2007
@@ -6454,16 +6454,25 @@
   while (Offset) {
 if (const StructType *STy = dyn_castStructType(GEPIdxTy)) {
   const StructLayout *SL = TD-getStructLayout(STy);
-  unsigned Elt = SL-getElementContainingOffset(Offset);
-  NewIndices.push_back(ConstantInt::get(Type::Int32Ty, Elt));
+  if (Offset  (int64_t)SL-getSizeInBytes()) {
+unsigned Elt = SL-getElementContainingOffset(Offset);
+NewIndices.push_back(ConstantInt::get(Type::Int32Ty, Elt));
   
-  Offset -= SL-getElementOffset(Elt);
-  GEPIdxTy = STy-getElementType(Elt);
+Offset -= SL-getElementOffset(Elt);
+GEPIdxTy = STy-getElementType(Elt);
+  } else {
+// Otherwise, we can't index into this, bail out.
+Offset = 0;
+OrigBase = 0;
+  }
 } else if (isaArrayType(GEPIdxTy) || isaVectorType(GEPIdxTy)) {
   const SequentialType *STy = castSequentialType(GEPIdxTy);
-  uint64_t EltSize = TD-getTypeSize(STy-getElementType());
-  NewIndices.push_back(ConstantInt::get(IntPtrTy, Offset/EltSize));
-  Offset %= EltSize;
+  if (uint64_t EltSize = TD-getTypeSize(STy-getElementType())) {
+
NewIndices.push_back(ConstantInt::get(IntPtrTy,Offset/EltSize));
+Offset %= EltSize;
+  } else {
+NewIndices.push_back(ConstantInt::get(IntPtrTy, 0));
+  }
   GEPIdxTy = STy-getElementType();
 } else {
   // Otherwise, we can't index into this, bail out.



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-05-11 Thread Chris Lattner


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.763 - 1.764
---
Log message:

fix regressions from my previous checking, including 
Transforms/InstCombine/2006-12-08-ICmp-Combining.ll



---
Diffs of the changes:  (+2 -2)

 InstructionCombining.cpp |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.763 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.764
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.763   Fri May 11 
00:55:56 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Fri May 11 11:58:45 2007
@@ -3926,9 +3926,9 @@
   ICmpInst *LHS = castICmpInst(Op0);
   bool NeedsSwap;
   if (ICmpInst::isSignedPredicate(LHSCC))
-NeedsSwap = LHSCst-getValue().sgt(LHSCst-getValue());
+NeedsSwap = LHSCst-getValue().sgt(RHSCst-getValue());
   else
-NeedsSwap = LHSCst-getValue().ugt(LHSCst-getValue());
+NeedsSwap = LHSCst-getValue().ugt(RHSCst-getValue());
 
   if (NeedsSwap) {
 std::swap(LHS, RHS);



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp LoopRotation.cpp

2007-05-11 Thread Dan Gohman


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.764 - 1.765
LoopRotation.cpp updated: 1.13 - 1.14
---
Log message:

Fix typos.


---
Diffs of the changes:  (+3 -3)

 InstructionCombining.cpp |2 +-
 LoopRotation.cpp |4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.764 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.765
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.764   Fri May 11 
11:58:45 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Fri May 11 16:10:54 2007
@@ -6373,7 +6373,7 @@
   if (isaUndefValue(Src))   // cast undef - undef
 return ReplaceInstUsesWith(CI, UndefValue::get(CI.getType()));
 
-  // Many cases of cast of a cast are eliminable. If its eliminable we just
+  // Many cases of cast of a cast are eliminable. If it's eliminable we just
   // eliminate it now.
   if (CastInst *CSrc = dyn_castCastInst(Src)) {   // A-B-C cast
 if (Instruction::CastOps opc = 


Index: llvm/lib/Transforms/Scalar/LoopRotation.cpp
diff -u llvm/lib/Transforms/Scalar/LoopRotation.cpp:1.13 
llvm/lib/Transforms/Scalar/LoopRotation.cpp:1.14
--- llvm/lib/Transforms/Scalar/LoopRotation.cpp:1.13Wed May  2 20:11:54 2007
+++ llvm/lib/Transforms/Scalar/LoopRotation.cpp Fri May 11 16:10:54 2007
@@ -116,7 +116,7 @@
   return RotatedOneLoop;
 }
 
-/// Rotate loop LP. Return true if it loop is rotated.
+/// Rotate loop LP. Return true if the loop is rotated.
 bool LoopRotate::rotateLoop(Loop *Lp, LPPassManager LPM) {
 
   L = Lp;
@@ -130,7 +130,7 @@
 return false;
 
   assert (OrigHeader  OrigLatch  OrigPreHeader 
-  Loop is not in cannocial form);
+  Loop is not in canonical form);
 
   // If loop header is not one of the loop exit block then
   // either this loop is already rotated or it is not 



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-05-10 Thread Chris Lattner


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.762 - 1.763
---
Log message:

fix Transforms/InstCombine/2007-05-10-icmp-or.ll


---
Diffs of the changes:  (+10 -5)

 InstructionCombining.cpp |   15 ++-
 1 files changed, 10 insertions(+), 5 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.762 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.763
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.762   Sun May  6 
08:37:16 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Fri May 11 00:55:56 2007
@@ -3919,13 +3919,18 @@
 LHSCC != ICmpInst::ICMP_UGE  LHSCC != ICmpInst::ICMP_ULE 
 RHSCC != ICmpInst::ICMP_UGE  RHSCC != ICmpInst::ICMP_ULE 
 LHSCC != ICmpInst::ICMP_SGE  LHSCC != ICmpInst::ICMP_SLE 
-RHSCC != ICmpInst::ICMP_SGE  RHSCC != ICmpInst::ICMP_SLE) {
+RHSCC != ICmpInst::ICMP_SGE  RHSCC != ICmpInst::ICMP_SLE 
+// We can't fold (ugt x, C) | (sgt x, C2).
+PredicatesFoldable(LHSCC, RHSCC)) {
   // Ensure that the larger constant is on the RHS.
-  ICmpInst::Predicate GT = ICmpInst::isSignedPredicate(LHSCC) ? 
-ICmpInst::ICMP_SGT : ICmpInst::ICMP_UGT;
-  Constant *Cmp = ConstantExpr::getICmp(GT, LHSCst, RHSCst);
   ICmpInst *LHS = castICmpInst(Op0);
-  if (castConstantInt(Cmp)-getZExtValue()) {
+  bool NeedsSwap;
+  if (ICmpInst::isSignedPredicate(LHSCC))
+NeedsSwap = LHSCst-getValue().sgt(LHSCst-getValue());
+  else
+NeedsSwap = LHSCst-getValue().ugt(LHSCst-getValue());
+
+  if (NeedsSwap) {
 std::swap(LHS, RHS);
 std::swap(LHSCst, RHSCst);
 std::swap(LHSCC, RHSCC);



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-05-06 Thread Chris Lattner


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.760 - 1.761
---
Log message:

Fix a bug in my previous patch


---
Diffs of the changes:  (+1 -1)

 InstructionCombining.cpp |2 +-
 1 files changed, 1 insertion(+), 1 deletion(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.760 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.761
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.760   Sat May  5 
17:41:33 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Sun May  6 02:24:03 2007
@@ -5600,7 +5600,7 @@
  castIntegerType(DestTy)-getBitWidth()) {
 Value *RHSOp = 0;
 if (Constant *RHSC = dyn_castConstant(ICI.getOperand(1))) {
-  RHSOp = ConstantExpr::getPtrToInt(RHSC, SrcTy);
+  RHSOp = ConstantExpr::getIntToPtr(RHSC, SrcTy);
 } else if (PtrToIntInst *RHSC = dyn_castPtrToIntInst(ICI.getOperand(1))) 
{
   RHSOp = RHSC-getOperand(0);
   // If the pointer types don't match, insert a bitcast.



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-05-05 Thread Chris Lattner


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.759 - 1.760
---
Log message:

Implement Transforms/InstCombine/cast_ptr.ll


---
Diffs of the changes:  (+22 -1)

 InstructionCombining.cpp |   23 ++-
 1 files changed, 22 insertions(+), 1 deletion(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.759 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.760
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.759   Sat May  5 
17:32:24 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Sat May  5 17:41:33 2007
@@ -5593,7 +5593,28 @@
   const Type *DestTy= LHSCI-getType();
   Value *RHSCIOp;
 
-  // We only handle extension cast instructions, so far. Enforce this.
+  // Turn icmp (ptrtoint x), (ptrtoint/c) into a compare of the input if the 
+  // integer type is the same size as the pointer type.
+  if (LHSCI-getOpcode() == Instruction::PtrToInt 
+  getTargetData().getPointerSizeInBits() == 
+ castIntegerType(DestTy)-getBitWidth()) {
+Value *RHSOp = 0;
+if (Constant *RHSC = dyn_castConstant(ICI.getOperand(1))) {
+  RHSOp = ConstantExpr::getPtrToInt(RHSC, SrcTy);
+} else if (PtrToIntInst *RHSC = dyn_castPtrToIntInst(ICI.getOperand(1))) 
{
+  RHSOp = RHSC-getOperand(0);
+  // If the pointer types don't match, insert a bitcast.
+  if (LHSCIOp-getType() != RHSOp-getType())
+RHSOp = InsertCastBefore(Instruction::BitCast, RHSOp,
+ LHSCIOp-getType(), ICI);
+}
+
+if (RHSOp)
+  return new ICmpInst(ICI.getPredicate(), LHSCIOp, RHSOp);
+  }
+  
+  // The code below only handles extension cast instructions, so far.
+  // Enforce this.
   if (LHSCI-getOpcode() != Instruction::ZExt 
   LHSCI-getOpcode() != Instruction::SExt)
 return 0;



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-05-04 Thread Chris Lattner


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.757 - 1.758
---
Log message:

Fix InstCombine/2007-05-04-Crash.ll and PR1384: http://llvm.org/PR1384 


---
Diffs of the changes:  (+14 -10)

 InstructionCombining.cpp |   24 ++--
 1 files changed, 14 insertions(+), 10 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.757 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.758
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.757   Wed May  2 
20:11:54 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Fri May  4 20:59:31 2007
@@ -6404,21 +6404,25 @@
 if (GEPIdxTy-isSized()) {
   SmallVectorValue*, 8 NewIndices;
   
-  // Start with the index over the outer type.
+  // Start with the index over the outer type.  Note that the type size
+  // might be zero (even if the offset isn't zero) if the indexed type
+  // is something like [0 x {int, int}]
   const Type *IntPtrTy = TD-getIntPtrType();
-  int64_t TySize = TD-getTypeSize(GEPIdxTy);
-  int64_t FirstIdx = Offset/TySize;
-  Offset %= TySize;
+  int64_t FirstIdx = 0;
+  if (int64_t TySize = TD-getTypeSize(GEPIdxTy)) {
+FirstIdx = Offset/TySize;
+Offset %= TySize;
   
-  // Handle silly modulus not returning values values [0..TySize).
-  if (Offset  0) {
---FirstIdx;
-Offset += TySize;
-assert(Offset = 0);
+// Handle silly modulus not returning values values [0..TySize).
+if (Offset  0) {
+  --FirstIdx;
+  Offset += TySize;
+  assert(Offset = 0);
+}
+assert((uint64_t)Offset  (uint64_t)TySize  Out of range 
offset);
   }
   
   NewIndices.push_back(ConstantInt::get(IntPtrTy, FirstIdx));
-  assert((uint64_t)Offset  (uint64_t)TySize  Out of range offset);
 
   // Index into the types.  If we fail, set OrigBase to null.
   while (Offset) {



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-04-27 Thread Chris Lattner


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.749 - 1.750
---
Log message:

refactor some code relating to pointer cast xforms, pulling it out of the 
codepath
for unrelated casts.


---
Diffs of the changes:  (+56 -53)

 InstructionCombining.cpp |  109 ---
 1 files changed, 56 insertions(+), 53 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.749 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.750
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.749   Thu Apr 19 
00:39:12 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Fri Apr 27 12:44:50 2007
@@ -193,6 +193,7 @@
  BinaryOperator I);
 Instruction *commonCastTransforms(CastInst CI);
 Instruction *commonIntCastTransforms(CastInst CI);
+Instruction *commonPointerCastTransforms(CastInst CI);
 Instruction *visitTrunc(TruncInst CI);
 Instruction *visitZExt(ZExtInst CI);
 Instruction *visitSExt(SExtInst CI);
@@ -204,7 +205,7 @@
 Instruction *visitSIToFP(CastInst CI);
 Instruction *visitPtrToInt(CastInst CI);
 Instruction *visitIntToPtr(CastInst CI);
-Instruction *visitBitCast(CastInst CI);
+Instruction *visitBitCast(BitCastInst CI);
 Instruction *FoldSelectOpOp(SelectInst SI, Instruction *TI,
 Instruction *FI);
 Instruction *visitSelectInst(SelectInst CI);
@@ -350,7 +351,7 @@
   bool isSub, Instruction I);
 Instruction *InsertRangeTest(Value *V, Constant *Lo, Constant *Hi,
  bool isSigned, bool Inside, Instruction IB);
-Instruction *PromoteCastOfAllocation(CastInst CI, AllocationInst AI);
+Instruction *PromoteCastOfAllocation(BitCastInst CI, AllocationInst AI);
 Instruction *MatchBSwap(BinaryOperator I);
 bool SimplifyStoreAtEndOfBlock(StoreInst SI);
 
@@ -6085,10 +6086,9 @@
 
 /// PromoteCastOfAllocation - If we find a cast of an allocation instruction,
 /// try to eliminate the cast by moving the type information into the alloc.
-Instruction *InstCombiner::PromoteCastOfAllocation(CastInst CI,
+Instruction *InstCombiner::PromoteCastOfAllocation(BitCastInst CI,
AllocationInst AI) {
-  const PointerType *PTy = dyn_castPointerType(CI.getType());
-  if (!PTy) return 0;   // Not casting the allocation to a pointer type.
+  const PointerType *PTy = castPointerType(CI.getType());
   
   // Remove any uses of AI that are dead.
   assert(!CI.use_empty()  Dead instructions should be removed earlier!);
@@ -6326,18 +6326,28 @@
 }
   }
 
+  // If we are casting a select then fold the cast into the select
+  if (SelectInst *SI = dyn_castSelectInst(Src))
+if (Instruction *NV = FoldOpIntoSelect(CI, SI, this))
+  return NV;
+
+  // If we are casting a PHI then fold the cast into the PHI
+  if (isaPHINode(Src))
+if (Instruction *NV = FoldOpIntoPhi(CI))
+  return NV;
+  
+  return 0;
+}
+
+/// @brief Implement the transforms for cast of pointer (bitcast/ptrtoint)
+Instruction *InstCombiner::commonPointerCastTransforms(CastInst CI) {
+  Value *Src = CI.getOperand(0);
+  
   // If casting the result of a getelementptr instruction with no offset, turn
   // this into a cast of the original pointer!
   //
   if (GetElementPtrInst *GEP = dyn_castGetElementPtrInst(Src)) {
-bool AllZeroOperands = true;
-for (unsigned i = 1, e = GEP-getNumOperands(); i != e; ++i)
-  if (!isaConstant(GEP-getOperand(i)) ||
-  !castConstant(GEP-getOperand(i))-isNullValue()) {
-AllZeroOperands = false;
-break;
-  }
-if (AllZeroOperands) {
+if (GEP-hasAllZeroIndices()) {
   // Changing the cast operand is usually not a good idea but it is safe
   // here because the pointer operand is being replaced with another 
   // pointer operand so the opcode doesn't need to change.
@@ -6346,24 +6356,10 @@
 }
   }
 
-  // If we are casting a malloc or alloca to a pointer to a type of the same
-  // size, rewrite the allocation instruction to allocate the right type.
-  if (AllocationInst *AI = dyn_castAllocationInst(Src))
-if (Instruction *V = PromoteCastOfAllocation(CI, *AI))
-  return V;
+  return commonCastTransforms(CI);
+}
 
-  // If we are casting a select then fold the cast into the select
-  if (SelectInst *SI = dyn_castSelectInst(Src))
-if (Instruction *NV = FoldOpIntoSelect(CI, SI, this))
-  return NV;
 
-  // If we are casting a PHI then fold the cast into the PHI
-  if (isaPHINode(Src))
-if (Instruction *NV = FoldOpIntoPhi(CI))
-  return NV;
-  
-  return 0;
-}
 
 /// Only the TRUNC, ZEXT, SEXT, and BITCAST can both operand and result as
 /// integer types. This function implements the common transforms for all those
@@ -6786,15 +6782,14 @@
 }
 
 

[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-04-27 Thread Chris Lattner


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.750 - 1.751
---
Log message:

Implement PR1345: http://llvm.org/PR1345  and 
Transforms/InstCombine/bitcast-gep.ll


---
Diffs of the changes:  (+104 -28)

 InstructionCombining.cpp |  132 +--
 1 files changed, 104 insertions(+), 28 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.750 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.751
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.750   Fri Apr 27 
12:44:50 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Fri Apr 27 19:57:34 2007
@@ -4358,15 +4358,27 @@
   }
 } else {
   // Convert to correct type.
-  Op = IC.InsertNewInstBefore(CastInst::createSExtOrBitCast(Op, IntPtrTy,
-   Op-getName()+.c), I);
-  if (Size != 1)
-// We'll let instcombine(mul) convert this to a shl if possible.
-Op = IC.InsertNewInstBefore(BinaryOperator::createMul(Op, Scale,
+  if (Op-getType() != IntPtrTy) {
+if (Constant *OpC = dyn_castConstant(Op))
+  Op = ConstantExpr::getSExt(OpC, IntPtrTy);
+else
+  Op = IC.InsertNewInstBefore(new SExtInst(Op, IntPtrTy,
+   Op-getName()+.c), I);
+  }
+  if (Size != 1) {
+if (Constant *OpC = dyn_castConstant(Op))
+  Op = ConstantExpr::getMul(OpC, Scale);
+else// We'll let instcombine(mul) convert this to a shl if 
possible.
+  Op = IC.InsertNewInstBefore(BinaryOperator::createMul(Op, Scale,
 GEP-getName()+.idx), I);
+  }
 
   // Emit an add instruction.
-  Result = IC.InsertNewInstBefore(BinaryOperator::createAdd(Op, Result,
+  if (isaConstant(Op)  isaConstant(Result))
+Result = ConstantExpr::getAdd(castConstant(Op),
+  castConstant(Result));
+  else
+Result = IC.InsertNewInstBefore(BinaryOperator::createAdd(Op, Result,
 GEP-getName()+.offs), 
I);
 }
   }
@@ -6343,17 +6355,96 @@
 Instruction *InstCombiner::commonPointerCastTransforms(CastInst CI) {
   Value *Src = CI.getOperand(0);
   
-  // If casting the result of a getelementptr instruction with no offset, turn
-  // this into a cast of the original pointer!
-  //
   if (GetElementPtrInst *GEP = dyn_castGetElementPtrInst(Src)) {
+// If casting the result of a getelementptr instruction with no offset, 
turn
+// this into a cast of the original pointer!
 if (GEP-hasAllZeroIndices()) {
   // Changing the cast operand is usually not a good idea but it is safe
   // here because the pointer operand is being replaced with another 
   // pointer operand so the opcode doesn't need to change.
+  AddToWorkList(GEP);
   CI.setOperand(0, GEP-getOperand(0));
   return CI;
 }
+
+// If the GEP has a single use, and the base pointer is a bitcast, and the
+// GEP computes a constant offset, see if we can convert these three
+// instructions into fewer.  This typically happens with unions and other
+// non-type-safe code.
+if (GEP-hasOneUse()  isaBitCastInst(GEP-getOperand(0))) {
+  if (GEP-hasAllConstantIndices()) {
+// We are guaranteed to get a constant from EmitGEPOffset.
+ConstantInt *OffsetV = castConstantInt(EmitGEPOffset(GEP, CI, 
*this));
+int64_t Offset = OffsetV-getSExtValue();
+
+// Get the base pointer input of the bitcast, and the type it points 
to.
+Value *OrigBase = castBitCastInst(GEP-getOperand(0))-getOperand(0);
+const Type *GEPIdxTy =
+  castPointerType(OrigBase-getType())-getElementType();
+if (GEPIdxTy-isSized()) {
+  SmallVectorValue*, 8 NewIndices;
+  
+  // Start with the index over the outer type.
+  const Type *IntPtrTy = TD-getIntPtrType();
+  int64_t TySize = TD-getTypeSize(GEPIdxTy);
+  int64_t FirstIdx = Offset/TySize;
+  Offset %= TySize;
+  
+  // Handle silly modulus not returning values values [0..TySize).
+  if (Offset  0) {
+assert(FirstIdx == 0);
+FirstIdx = -1;
+Offset += TySize;
+assert(Offset = 0);
+  }
+  
+  NewIndices.push_back(ConstantInt::get(IntPtrTy, FirstIdx));
+  assert((uint64_t)Offset  (uint64_t)TySize  Out of range offset);
+
+  // Index into the types.  If we fail, set OrigBase to null.
+  while (Offset) {
+if (const StructType *STy = dyn_castStructType(GEPIdxTy)) {
+  const StructLayout *SL = TD-getStructLayout(STy);
+  unsigned Elt = SL-getElementContainingOffset(Offset);
+ 

Re: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-04-27 Thread Nick Lewycky
Chris Lattner wrote:
 +  if (OrigBase) {
 +// If we were able to index down into an element, create the GEP
 +// and bitcast the result.  This eliminates one bitcast, 
 potentially
 +// two.
 +Instruction *NGEP = new GetElementPtrInst(OrigBase, 
 NewIndices[0],
 +  NewIndices.size(), );
 +InsertNewInstBefore(NGEP, CI);
 +NGEP-takeName(GEP);
 +
 +cerr  \nZAP:   *GEP-getOperand(0);
 +cerr  ZAP:   *GEP;
 +cerr  ZAP:   CI  \n;
 +
 +cerr  NEW:   *NGEP  \n;
   
How rude! ;-)
 +
 +if (isaBitCastInst(CI))
 +  return new BitCastInst(NGEP, CI.getType());
 +assert(isaPtrToIntInst(CI));
 +return new PtrToIntInst(NGEP, CI.getType());
 +  }
 +}
 +  }  
 +}
}
  
return commonCastTransforms(CI);
 @@ -7306,10 +7397,7 @@
  if (isaPointerType(CI-getOperand(0)-getType()))
return GetKnownAlignment(CI-getOperand(0), TD);
  return 0;
 -  } else if (isaGetElementPtrInst(V) ||
 - (isaConstantExpr(V)  
 -  
 castConstantExpr(V)-getOpcode()==Instruction::GetElementPtr)) {
 -User *GEPI = castUser(V);
 +  } else if (User *GEPI = dyn_castGetElementPtr(V)) {
   
Did the email get mangled, or does it actually say that? cvsweb agrees 
with the email.
  unsigned BaseAlignment = GetKnownAlignment(GEPI-getOperand(0), TD);
  if (BaseAlignment == 0) return 0;
  
 @@ -8107,7 +8195,7 @@
  
  Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst GEP) {
Value *PtrOp = GEP.getOperand(0);
 -  // Is it 'getelementptr %P, long 0'  or 'getelementptr %P'
 +  // Is it 'getelementptr %P, i32 0'  or 'getelementptr %P'
// If so, eliminate the noop.
if (GEP.getNumOperands() == 1)
  return ReplaceInstUsesWith(GEP, PtrOp);
 @@ -8122,22 +8210,11 @@
if (GEP.getNumOperands() == 2  HasZeroPointerIndex)
  return ReplaceInstUsesWith(GEP, PtrOp);
  
 -  // Keep track of whether all indices are zero constants integers.
 -  bool AllZeroIndices = true;
 -  
// Eliminate unneeded casts for indices.
bool MadeChange = false;

gep_type_iterator GTI = gep_type_begin(GEP);
for (unsigned i = 1, e = GEP.getNumOperands(); i != e; ++i, ++GTI) {
 -// Track whether this GEP has all zero indices, if so, it doesn't move 
 the
 -// input pointer, it just changes its type.
 -if (AllZeroIndices) {
 -  if (ConstantInt *CI = dyn_castConstantInt(GEP.getOperand(i)))
 -AllZeroIndices = CI-isZero();
 -  else
 -AllZeroIndices = false;
 -}
  if (isaSequentialType(*GTI)) {
if (CastInst *CI = dyn_castCastInst(GEP.getOperand(i))) {
  if (CI-getOpcode() == Instruction::ZExt ||
 @@ -8173,7 +8250,7 @@
// If this GEP instruction doesn't move the pointer, and if the input 
 operand
// is a bitcast of another pointer, just replace the GEP with a bitcast of 
 the
// real input to the dest type.
 -  if (AllZeroIndices  isaBitCastInst(GEP.getOperand(0)))
 +  if (GEP.hasAllZeroIndices()  isaBitCastInst(GEP.getOperand(0)))
  return new 
 BitCastInst(castBitCastInst(GEP.getOperand(0))-getOperand(0),
 GEP.getType());
  
 @@ -8573,8 +8650,7 @@
}
  
if (GetElementPtrInst *GEPI = dyn_castGetElementPtrInst(Op))
 -if (isaConstantPointerNull(GEPI-getOperand(0)) ||
 -isaUndefValue(GEPI-getOperand(0))) {
 +if (isaConstantPointerNull(GEPI-getOperand(0))) {
// Insert a new store to null instruction before the load to indicate
// that this code is not reachable.  We do this instead of inserting
// an unreachable instruction directly because we cannot modify the



   
___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


Re: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-04-27 Thread Chris Lattner

On Apr 27, 2007, at 8:44 PM, Nick Lewycky wrote:

 Chris Lattner wrote:
 +  if (OrigBase) {
 +// If we were able to index down into an element,  
 create the GEP
 +// and bitcast the result.  This eliminates one  
 bitcast, potentially
 +// two.
 +Instruction *NGEP = new GetElementPtrInst(OrigBase,  
 NewIndices[0],
 +   
 NewIndices.size(), );
 +InsertNewInstBefore(NGEP, CI);
 +NGEP-takeName(GEP);
 +
 +cerr  \nZAP:   *GEP-getOperand(0);
 +cerr  ZAP:   *GEP;
 +cerr  ZAP:   CI  \n;
 +
 +cerr  NEW:   *NGEP  \n;

 How rude! ;-)

holy crap batman.  Fixed.

  return 0;
 -  } else if (isaGetElementPtrInst(V) ||
 - (isaConstantExpr(V) 
 -  castConstantExpr(V)-getOpcode() 
 ==Instruction::GetElementPtr)) {
 -User *GEPI = castUser(V);
 +  } else if (User *GEPI = dyn_castGetElementPtr(V)) {

 Did the email get mangled, or does it actually say that? cvsweb agrees
 with the email.

the diff is right.  dyn_castGetElementPtr is a helper function in  
instcombine.

-Chris
___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-04-27 Thread Chris Lattner


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.752 - 1.753
---
Log message:

Fix several latent bugs in EmitGEPOffset that didn't manifest with its
previous clients.  This fixes MallocBench/gs


---
Diffs of the changes:  (+51 -35)

 InstructionCombining.cpp |   86 +++
 1 files changed, 51 insertions(+), 35 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.752 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.753
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.752   Fri Apr 27 
22:50:56 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Fri Apr 27 23:52:43 2007
@@ -4337,50 +4337,66 @@
   Value *Result = Constant::getNullValue(IntPtrTy);
 
   // Build a mask for high order bits.
-  uint64_t PtrSizeMask = ~0ULL  (64-TD.getPointerSize()*8);
+  unsigned IntPtrWidth = TD.getPointerSize()*8;
+  uint64_t PtrSizeMask = ~0ULL  (64-IntPtrWidth);
 
   for (unsigned i = 1, e = GEP-getNumOperands(); i != e; ++i, ++GTI) {
 Value *Op = GEP-getOperand(i);
 uint64_t Size = TD.getTypeSize(GTI.getIndexedType())  PtrSizeMask;
-Constant *Scale = ConstantInt::get(IntPtrTy, Size);
-if (Constant *OpC = dyn_castConstant(Op)) {
-  if (!OpC-isNullValue()) {
-OpC = ConstantExpr::getIntegerCast(OpC, IntPtrTy, true /*SExt*/);
-Scale = ConstantExpr::getMul(OpC, Scale);
-if (Constant *RC = dyn_castConstant(Result))
-  Result = ConstantExpr::getAdd(RC, Scale);
-else {
-  // Emit an add instruction.
-  Result = IC.InsertNewInstBefore(
- BinaryOperator::createAdd(Result, Scale,
-   GEP-getName()+.offs), I);
-}
-  }
-} else {
-  // Convert to correct type.
-  if (Op-getType() != IntPtrTy) {
-if (Constant *OpC = dyn_castConstant(Op))
-  Op = ConstantExpr::getSExt(OpC, IntPtrTy);
+if (ConstantInt *OpC = dyn_castConstantInt(Op)) {
+  if (OpC-isZero()) continue;
+  
+  // Handle a struct index, which adds its field offset to the pointer.
+  if (const StructType *STy = dyn_castStructType(*GTI)) {
+Size = TD.getStructLayout(STy)-getElementOffset(OpC-getZExtValue());
+
+if (ConstantInt *RC = dyn_castConstantInt(Result))
+  Result = ConstantInt::get(RC-getValue() + APInt(IntPtrWidth, Size));
 else
-  Op = IC.InsertNewInstBefore(new SExtInst(Op, IntPtrTy,
-   Op-getName()+.c), I);
+  Result = IC.InsertNewInstBefore(
+   BinaryOperator::createAdd(Result,
+ ConstantInt::get(IntPtrTy, Size),
+ GEP-getName()+.offs), I);
+continue;
   }
-  if (Size != 1) {
-if (Constant *OpC = dyn_castConstant(Op))
-  Op = ConstantExpr::getMul(OpC, Scale);
-else// We'll let instcombine(mul) convert this to a shl if 
possible.
-  Op = IC.InsertNewInstBefore(BinaryOperator::createMul(Op, Scale,
-GEP-getName()+.idx), I);
+  
+  Constant *Scale = ConstantInt::get(IntPtrTy, Size);
+  Constant *OC = ConstantExpr::getIntegerCast(OpC, IntPtrTy, true 
/*SExt*/);
+  Scale = ConstantExpr::getMul(OC, Scale);
+  if (Constant *RC = dyn_castConstant(Result))
+Result = ConstantExpr::getAdd(RC, Scale);
+  else {
+// Emit an add instruction.
+Result = IC.InsertNewInstBefore(
+   BinaryOperator::createAdd(Result, Scale,
+ GEP-getName()+.offs), I);
   }
-
-  // Emit an add instruction.
-  if (isaConstant(Op)  isaConstant(Result))
-Result = ConstantExpr::getAdd(castConstant(Op),
-  castConstant(Result));
+  continue;
+}
+// Convert to correct type.
+if (Op-getType() != IntPtrTy) {
+  if (Constant *OpC = dyn_castConstant(Op))
+Op = ConstantExpr::getSExt(OpC, IntPtrTy);
   else
-Result = IC.InsertNewInstBefore(BinaryOperator::createAdd(Op, Result,
-GEP-getName()+.offs), 
I);
+Op = IC.InsertNewInstBefore(new SExtInst(Op, IntPtrTy,
+ Op-getName()+.c), I);
 }
+if (Size != 1) {
+  Constant *Scale = ConstantInt::get(IntPtrTy, Size);
+  if (Constant *OpC = dyn_castConstant(Op))
+Op = ConstantExpr::getMul(OpC, Scale);
+  else// We'll let instcombine(mul) convert this to a shl if possible.
+Op = IC.InsertNewInstBefore(BinaryOperator::createMul(Op, Scale,
+  GEP-getName()+.idx), I);
+}
+
+// Emit an add instruction.
+if 

[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-04-27 Thread Chris Lattner


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.753 - 1.754
---
Log message:

fix a bug triggered by 403.gcc


---
Diffs of the changes:  (+1 -2)

 InstructionCombining.cpp |3 +--
 1 files changed, 1 insertion(+), 2 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.753 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.754
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.753   Fri Apr 27 
23:52:43 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Sat Apr 28 00:27:36 2007
@@ -6408,8 +6408,7 @@
   
   // Handle silly modulus not returning values values [0..TySize).
   if (Offset  0) {
-assert(FirstIdx == 0);
-FirstIdx = -1;
+--FirstIdx;
 Offset += TySize;
 assert(Offset = 0);
   }



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp ScalarReplAggregates.cpp

2007-04-18 Thread Zhou Sheng


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.748 - 1.749
ScalarReplAggregates.cpp updated: 1.84 - 1.85
---
Log message:

Make use of ConstantInt::isZero instead of ConstantInt::isNullValue.


---
Diffs of the changes:  (+5 -5)

 InstructionCombining.cpp |8 
 ScalarReplAggregates.cpp |2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.748 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.749
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.748   Sat Apr 14 
20:02:18 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Thu Apr 19 00:39:12 2007
@@ -2224,7 +2224,7 @@
   // 0 - (X sdiv C)  - (X sdiv -C)
   if (Op1I-getOpcode() == Instruction::SDiv)
 if (ConstantInt *CSI = dyn_castConstantInt(Op0))
-  if (CSI-isNullValue())
+  if (CSI-isZero())
 if (Constant *DivRHS = dyn_castConstant(Op1I-getOperand(1)))
   return BinaryOperator::createSDiv(Op1I-getOperand(0),
ConstantExpr::getNeg(DivRHS));
@@ -2268,7 +2268,7 @@
   switch (pred) {
 case ICmpInst::ICMP_SLT: 
   // True if LHS s RHS and RHS == 0
-  return RHS-isNullValue();
+  return RHS-isZero();
 case ICmpInst::ICMP_SLE: 
   // True if LHS s= RHS and RHS == -1
   return RHS-isAllOnesValue();
@@ -2303,7 +2303,7 @@
 return BinaryOperator::createMul(SI-getOperand(0),
  ConstantExpr::getShl(CI, ShOp));
 
-  if (CI-isNullValue())
+  if (CI-isZero())
 return ReplaceInstUsesWith(I, Op1);  // X * 0  == 0
   if (CI-equalsInt(1))  // X * 1  == X
 return ReplaceInstUsesWith(I, Op0);
@@ -8131,7 +8131,7 @@
 // input pointer, it just changes its type.
 if (AllZeroIndices) {
   if (ConstantInt *CI = dyn_castConstantInt(GEP.getOperand(i)))
-AllZeroIndices = CI-isNullValue();
+AllZeroIndices = CI-isZero();
   else
 AllZeroIndices = false;
 }


Index: llvm/lib/Transforms/Scalar/ScalarReplAggregates.cpp
diff -u llvm/lib/Transforms/Scalar/ScalarReplAggregates.cpp:1.84 
llvm/lib/Transforms/Scalar/ScalarReplAggregates.cpp:1.85
--- llvm/lib/Transforms/Scalar/ScalarReplAggregates.cpp:1.84Wed Apr 11 
10:45:25 2007
+++ llvm/lib/Transforms/Scalar/ScalarReplAggregates.cpp Thu Apr 19 00:39:12 2007
@@ -834,7 +834,7 @@
   } else if (GEP-getNumOperands() == 3  
  isaConstantInt(GEP-getOperand(1)) 
  isaConstantInt(GEP-getOperand(2)) 
- castConstant(GEP-getOperand(1))-isNullValue()) {
+ castConstantInt(GEP-getOperand(1))-isZero()) {
 // We are stepping into an element, e.g. a structure or an array:
 // GEP Ptr, int 0, uint C
 const Type *AggTy = PTy-getElementType();



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-04-14 Thread Chris Lattner


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.743 - 1.744
---
Log message:

Implement InstCombine/vec_demanded_elts.ll:test2.  This allows us to turn

unsigned test(float f) {
 return _mm_cvtsi128_si32( (__m128i) _mm_set_ss( f*f ));
}

into:

_test:
movss 4(%esp), %xmm0
mulss %xmm0, %xmm0
movd %xmm0, %eax
ret

instead of:

_test:
movss 4(%esp), %xmm0
mulss %xmm0, %xmm0
xorps %xmm1, %xmm1
movss %xmm0, %xmm1
movd %xmm1, %eax
ret

GCC gets:

_test:
subl$28, %esp
movss   32(%esp), %xmm0
mulss   %xmm0, %xmm0
xorps   %xmm1, %xmm1
movss   %xmm0, %xmm1
movaps  %xmm1, %xmm0
movd%xmm0, 12(%esp)
movl12(%esp), %eax
addl$28, %esp
ret




---
Diffs of the changes:  (+66 -0)

 InstructionCombining.cpp |   66 +++
 1 files changed, 66 insertions(+)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.743 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.744
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.743   Fri Apr 13 
19:20:02 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Sat Apr 14 17:29:23 2007
@@ -1489,7 +1489,73 @@
 UndefElts |= 1ULL  IdxNo;
 break;
   }
+  case Instruction::BitCast: {
+// Packed-packed casts only.
+const VectorType *VTy = dyn_castVectorType(I-getOperand(0)-getType());
+if (!VTy) break;
+unsigned InVWidth = VTy-getNumElements();
+uint64_t InputDemandedElts = 0;
+unsigned Ratio;
+
+if (VWidth == InVWidth) {
+  // If we are converting from 4x i32 - 4 x f32, we demand the same
+  // elements as are demanded of us.
+  Ratio = 1;
+  InputDemandedElts = DemandedElts;
+} else if (VWidth  InVWidth) {
+  // Untested so far.
+  break;
+  
+  // If there are more elements in the result than there are in the source,
+  // then an input element is live if any of the corresponding output
+  // elements are live.
+  Ratio = VWidth/InVWidth;
+  for (unsigned OutIdx = 0; OutIdx != VWidth; ++OutIdx) {
+if (DemandedElts  (1ULL  OutIdx))
+  InputDemandedElts |= 1ULL  (OutIdx/Ratio);
+  }
+} else {
+  // Untested so far.
+  break;
+  
+  // If there are more elements in the source than there are in the result,
+  // then an input element is live if the corresponding output element is
+  // live.
+  Ratio = InVWidth/VWidth;
+  for (unsigned InIdx = 0; InIdx != InVWidth; ++InIdx)
+if (DemandedElts  (1ULL  InIdx/Ratio))
+  InputDemandedElts |= 1ULL  InIdx;
+}
 
+// div/rem demand all inputs, because they don't want divide by zero.
+TmpV = SimplifyDemandedVectorElts(I-getOperand(0), InputDemandedElts,
+  UndefElts2, Depth+1);
+if (TmpV) {
+  I-setOperand(0, TmpV);
+  MadeChange = true;
+}
+
+UndefElts = UndefElts2;
+if (VWidth  InVWidth) {
+  assert(0  Unimp);
+  // If there are more elements in the result than there are in the source,
+  // then an output element is undef if the corresponding input element is
+  // undef.
+  for (unsigned OutIdx = 0; OutIdx != VWidth; ++OutIdx)
+if (UndefElts2  (1ULL  (OutIdx/Ratio)))
+  UndefElts |= 1ULL  OutIdx;
+} else if (VWidth  InVWidth) {
+  assert(0  Unimp);
+  // If there are more elements in the source than there are in the result,
+  // then a result element is undef if all of the corresponding input
+  // elements are undef.
+  UndefElts = ~0ULL  (64-VWidth);  // Start out all undef.
+  for (unsigned InIdx = 0; InIdx != InVWidth; ++InIdx)
+if ((UndefElts2  (1ULL  InIdx)) == 0)// Not undef?
+  UndefElts = ~(1ULL  (InIdx/Ratio));// Clear undef bit.
+}
+break;
+  }
   case Instruction::And:
   case Instruction::Or:
   case Instruction::Xor:



___
llvm-commits mailing list
[EMAIL PROTECTED]
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-04-14 Thread Chris Lattner


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.744 - 1.745
---
Log message:

Implement Transforms/InstCombine/vec_extract_elt.ll, transforming:

define i32 @test(float %f) {
%tmp7 = insertelement 4 x float undef, float %f, i32 0
%tmp17 = bitcast 4 x float %tmp7 to 4 x i32 
%tmp19 = extractelement 4 x i32 %tmp17, i32 0 
ret i32 %tmp19
}

into:

define i32 @test(float %f) {
%tmp19 = bitcast float %f to i32; i32 [#uses=1]
ret i32 %tmp19
}

On PPC, this is the difference between:

_test:
mfspr r2, 256
oris r3, r2, 8192
mtspr 256: http://llvm.org/PR256 , r3
stfs f1, -16(r1)
addi r3, r1, -16
addi r4, r1, -32
lvx v2, 0, r3
stvx v2, 0, r4
lwz r3, -32(r1)
mtspr 256: http://llvm.org/PR256 , r2
blr 

and:

_test:
stfs f1, -4(r1)
nop
nop
nop
lwz r3, -4(r1)
blr 



---
Diffs of the changes:  (+11 -0)

 InstructionCombining.cpp |   11 +++
 1 files changed, 11 insertions(+)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.744 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.745
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.744   Sat Apr 14 
17:29:23 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Sat Apr 14 18:02:14 2007
@@ -9109,6 +9109,17 @@
 
 if (Value *Elt = FindScalarElement(EI.getOperand(0), IndexVal))
   return ReplaceInstUsesWith(EI, Elt);
+
+// If the this extractelement is directly using a bitcast from a vector of
+// the same number of elements, see if we can find the source element from
+// it.  In this case, we will end up needing to bitcast the scalars.
+if (BitCastInst *BCI = dyn_castBitCastInst(EI.getOperand(0))) {
+  if (const VectorType *VT = 
+  dyn_castVectorType(BCI-getOperand(0)-getType()))
+if (VT-getNumElements() == VectorWidth)
+  if (Value *Elt = FindScalarElement(BCI-getOperand(0), IndexVal))
+return new BitCastInst(Elt, EI.getType());
+}
   }
   
   if (Instruction *I = dyn_castInstruction(EI.getOperand(0))) {



___
llvm-commits mailing list
[EMAIL PROTECTED]
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-04-14 Thread Chris Lattner


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.746 - 1.747
---
Log message:

refactor some code, no functionality change.


---
Diffs of the changes:  (+77 -58)

 InstructionCombining.cpp |  135 ++-
 1 files changed, 77 insertions(+), 58 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.746 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.747
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.746   Sat Apr 14 
18:32:02 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Sat Apr 14 19:07:55 2007
@@ -352,6 +352,7 @@
  bool isSigned, bool Inside, Instruction IB);
 Instruction *PromoteCastOfAllocation(CastInst CI, AllocationInst AI);
 Instruction *MatchBSwap(BinaryOperator I);
+bool SimplifyStoreAtEndOfBlock(StoreInst SI);
 
 Value *EvaluateInDifferentType(Value *V, const Type *Ty, bool isSigned);
   };
@@ -8818,68 +8819,86 @@
   // ends with an unconditional branch, try to move it to the successor block.
   BBI = SI; ++BBI;
   if (BranchInst *BI = dyn_castBranchInst(BBI))
-if (BI-isUnconditional()) {
-  // Check to see if the successor block has exactly two incoming edges.  
If
-  // so, see if the other predecessor contains a store to the same 
location.
-  // if so, insert a PHI node (if needed) and move the stores down.
-  BasicBlock *Dest = BI-getSuccessor(0);
-
-  pred_iterator PI = pred_begin(Dest);
-  BasicBlock *Other = 0;
-  if (*PI != BI-getParent())
-Other = *PI;
-  ++PI;
-  if (PI != pred_end(Dest)) {
-if (*PI != BI-getParent())
-  if (Other)
-Other = 0;
-  else
-Other = *PI;
-if (++PI != pred_end(Dest))
-  Other = 0;
-  }
-  if (Other) {  // If only one other pred...
-BBI = Other-getTerminator();
-// Make sure this other block ends in an unconditional branch and that
-// there is an instruction before the branch.
-if (isaBranchInst(BBI)  castBranchInst(BBI)-isUnconditional() 
-BBI != Other-begin()) {
-  --BBI;
-  StoreInst *OtherStore = dyn_castStoreInst(BBI);
-  
-  // If this instruction is a store to the same location.
-  if (OtherStore  OtherStore-getOperand(1) == SI.getOperand(1)) {
-// Okay, we know we can perform this transformation.  Insert a PHI
-// node now if we need it.
-Value *MergedVal = OtherStore-getOperand(0);
-if (MergedVal != SI.getOperand(0)) {
-  PHINode *PN = new PHINode(MergedVal-getType(), storemerge);
-  PN-reserveOperandSpace(2);
-  PN-addIncoming(SI.getOperand(0), SI.getParent());
-  PN-addIncoming(OtherStore-getOperand(0), Other);
-  MergedVal = InsertNewInstBefore(PN, Dest-front());
-}
-
-// Advance to a place where it is safe to insert the new store and
-// insert it.
-BBI = Dest-begin();
-while (isaPHINode(BBI)) ++BBI;
-InsertNewInstBefore(new StoreInst(MergedVal, SI.getOperand(1),
-  OtherStore-isVolatile()), *BBI);
-
-// Nuke the old stores.
-EraseInstFromFunction(SI);
-EraseInstFromFunction(*OtherStore);
-++NumCombined;
-return 0;
-  }
-}
-  }
-}
+if (BI-isUnconditional())
+  if (SimplifyStoreAtEndOfBlock(SI))
+return 0;  // xform done!
   
   return 0;
 }
 
+/// SimplifyStoreAtEndOfBlock - Turn things like:
+///   if () { *P = v1; } else { *P = v2 }
+/// into a phi node with a store in the successor.
+///
+bool InstCombiner::SimplifyStoreAtEndOfBlock(StoreInst SI) {
+  BasicBlock *StoreBB = SI.getParent();
+  
+  // Check to see if the successor block has exactly two incoming edges.  If
+  // so, see if the other predecessor contains a store to the same location.
+  // if so, insert a PHI node (if needed) and move the stores down.
+  BasicBlock *Dest = StoreBB-getTerminator()-getSuccessor(0);
+  
+  // Determine whether Dest has exactly two predecessors and, if so, compute
+  // the other predecessor.
+  pred_iterator PI = pred_begin(Dest);
+  BasicBlock *Other = 0;
+  if (*PI != StoreBB)
+Other = *PI;
+  ++PI;
+  if (PI == pred_end(Dest))
+return false;
+  
+  if (*PI != StoreBB) {
+if (Other)
+  return false;
+Other = *PI;
+  }
+  if (++PI != pred_end(Dest))
+return false;
+  
+  
+  BasicBlock::iterator BBI = Other-getTerminator();
+  BranchInst *OtherBr = dyn_castBranchInst(BBI);
+  
+  // Make sure this other block ends in an unconditional branch and that
+  // there is an instruction before the branch.
+  if (!OtherBr || !castBranchInst(BBI)-isUnconditional() ||
+   

[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-04-14 Thread Chris Lattner


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.747 - 1.748
---
Log message:

Extend store merging to support the 'if/then' version in addition to 
if/then/else.

This sinks the two stores in this example into a single store in cond_next.  In 
this
case, it allows elimination of the load as well:

store double 0.00e+00, double* @s.3060
%tmp3 = fcmp ogt double %tmp1, 5.00e-01 ; i1 [#uses=1]
br i1 %tmp3, label %cond_true, label %cond_next
cond_true:  ; preds = %entry
store double 1.00e+00, double* @s.3060
br label %cond_next
cond_next:  ; preds = %entry, %cond_true
%tmp6 = load double* @s.3060; double [#uses=1]

This implements Transforms/InstCombine/store-merge.ll:test2



---
Diffs of the changes:  (+60 -26)

 InstructionCombining.cpp |   86 ---
 1 files changed, 60 insertions(+), 26 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.747 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.748
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.747   Sat Apr 14 
19:07:55 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Sat Apr 14 20:02:18 2007
@@ -8830,64 +8830,98 @@
 ///   if () { *P = v1; } else { *P = v2 }
 /// into a phi node with a store in the successor.
 ///
+/// Simplify things like:
+///   *P = v1; if () { *P = v2; }
+/// into a phi node with a store in the successor.
+///
 bool InstCombiner::SimplifyStoreAtEndOfBlock(StoreInst SI) {
   BasicBlock *StoreBB = SI.getParent();
   
   // Check to see if the successor block has exactly two incoming edges.  If
   // so, see if the other predecessor contains a store to the same location.
   // if so, insert a PHI node (if needed) and move the stores down.
-  BasicBlock *Dest = StoreBB-getTerminator()-getSuccessor(0);
+  BasicBlock *DestBB = StoreBB-getTerminator()-getSuccessor(0);
   
   // Determine whether Dest has exactly two predecessors and, if so, compute
   // the other predecessor.
-  pred_iterator PI = pred_begin(Dest);
-  BasicBlock *Other = 0;
+  pred_iterator PI = pred_begin(DestBB);
+  BasicBlock *OtherBB = 0;
   if (*PI != StoreBB)
-Other = *PI;
+OtherBB = *PI;
   ++PI;
-  if (PI == pred_end(Dest))
+  if (PI == pred_end(DestBB))
 return false;
   
   if (*PI != StoreBB) {
-if (Other)
+if (OtherBB)
   return false;
-Other = *PI;
+OtherBB = *PI;
   }
-  if (++PI != pred_end(Dest))
+  if (++PI != pred_end(DestBB))
 return false;
   
   
-  BasicBlock::iterator BBI = Other-getTerminator();
+  // Verify that the other block ends in a branch and is not otherwise empty.
+  BasicBlock::iterator BBI = OtherBB-getTerminator();
   BranchInst *OtherBr = dyn_castBranchInst(BBI);
-  
-  // Make sure this other block ends in an unconditional branch and that
-  // there is an instruction before the branch.
-  if (!OtherBr || !castBranchInst(BBI)-isUnconditional() ||
-  BBI == Other-begin())
+  if (!OtherBr || BBI == OtherBB-begin())
 return false;
   
-  // See if the last instruction in other block is a store to the same 
location.
-  --BBI;
-  StoreInst *OtherStore = dyn_castStoreInst(BBI);
-  
-  // If this instruction is a store to the same location.
-  if (!OtherStore || OtherStore-getOperand(1) != SI.getOperand(1))
-return false;
+  // If the other block ends in an unconditional branch, check for the 'if then
+  // else' case.  there is an instruction before the branch.
+  StoreInst *OtherStore = 0;
+  if (OtherBr-isUnconditional()) {
+// If this isn't a store, or isn't a store to the same location, bail out.
+--BBI;
+OtherStore = dyn_castStoreInst(BBI);
+if (!OtherStore || OtherStore-getOperand(1) != SI.getOperand(1))
+  return false;
+  } else {
+// Otherwise, the other block ended with a conditional branch.  If one of 
the
+// destinations is StoreBB, then we have the if/then case.
+if (OtherBr-getSuccessor(0) != StoreBB  
+OtherBr-getSuccessor(1) != StoreBB)
+  return false;
+
+// Okay, we know that OtherBr now goes to Dest and StoreBB, so this is an
+// if/then triangle.  See if there is a store to the same ptr as SI that 
lives
+// in OtherBB.
+for (;; --BBI) {
+  // Check to see if we find the matching store.
+  if ((OtherStore = dyn_castStoreInst(BBI))) {
+if (OtherStore-getOperand(1) != SI.getOperand(1))
+  return false;
+break;
+  }
+  // If we find something that may be using the stored value, or if we run 
out
+  // of instructions, we can't do the xform.
+  if (isaLoadInst(BBI) || BBI-mayWriteToMemory() ||
+  BBI == OtherBB-begin())
+return false;
+}
+
+// In order to eliminate the store in OtherBr, we have to
+// make sure nothing reads the stored value in 

[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-04-13 Thread Chris Lattner


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.742 - 1.743
---
Log message:

Implement PR1201: http://llvm.org/PR1201  and 
test/Transforms/InstCombine/malloc-free-delete.ll


---
Diffs of the changes:  (+23 -8)

 InstructionCombining.cpp |   31 +++
 1 files changed, 23 insertions(+), 8 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.742 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.743
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.742   Wed Apr 11 
01:57:46 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Fri Apr 13 19:20:02 2007
@@ -8367,13 +8367,6 @@
 Instruction *InstCombiner::visitFreeInst(FreeInst FI) {
   Value *Op = FI.getOperand(0);
 
-  // Change free ty* (cast ty2* X to ty*) into free ty2* X
-  if (CastInst *CI = dyn_castCastInst(Op))
-if (isaPointerType(CI-getOperand(0)-getType())) {
-  FI.setOperand(0, CI-getOperand(0));
-  return FI;
-}
-
   // free undef - unreachable.
   if (isaUndefValue(Op)) {
 // Insert a new store to null because we cannot modify the CFG here.
@@ -8381,11 +8374,33 @@
   UndefValue::get(PointerType::get(Type::Int1Ty)), FI);
 return EraseInstFromFunction(FI);
   }
-
+  
   // If we have 'free null' delete the instruction.  This can happen in stl 
code
   // when lots of inlining happens.
   if (isaConstantPointerNull(Op))
 return EraseInstFromFunction(FI);
+  
+  // Change free ty* (cast ty2* X to ty*) into free ty2* X
+  if (BitCastInst *CI = dyn_castBitCastInst(Op)) {
+FI.setOperand(0, CI-getOperand(0));
+return FI;
+  }
+  
+  // Change free (gep X, 0,0,0,0) into free(X)
+  if (GetElementPtrInst *GEPI = dyn_castGetElementPtrInst(Op)) {
+if (GEPI-hasAllZeroIndices()) {
+  AddToWorkList(GEPI);
+  FI.setOperand(0, GEPI-getOperand(0));
+  return FI;
+}
+  }
+  
+  // Change free(malloc) into nothing, if the malloc has a single use.
+  if (MallocInst *MI = dyn_castMallocInst(Op))
+if (MI-hasOneUse()) {
+  EraseInstFromFunction(FI);
+  return EraseInstFromFunction(*MI);
+}
 
   return 0;
 }



___
llvm-commits mailing list
[EMAIL PROTECTED]
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-04-11 Thread Chris Lattner


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.739 - 1.740
---
Log message:

canonicalize (x u 2147483648) - (x s -1) and (x u 2147483647) - (x s 0)



---
Diffs of the changes:  (+32 -25)

 InstructionCombining.cpp |   57 ++-
 1 files changed, 32 insertions(+), 25 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.739 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.740
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.739   Wed Apr 11 
00:45:39 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Wed Apr 11 01:12:58 2007
@@ -4624,6 +4624,11 @@
 return new ICmpInst(ICmpInst::ICMP_NE, Op0,Op1);
   if (isMinValuePlusOne(CI,false))  // A u MIN+1 - A == MIN
 return new ICmpInst(ICmpInst::ICMP_EQ, Op0, SubOne(CI));
+  // (x u 2147483648) - (x s -1)  - true if sign bit clear
+  if (CI-isMinValue(true))
+return new ICmpInst(ICmpInst::ICMP_SGT, Op0,
+ConstantInt::getAllOnesValue(Op0-getType()));
+  
   break;
 
 case ICmpInst::ICMP_SLT:
@@ -4642,6 +4647,11 @@
 return new ICmpInst(ICmpInst::ICMP_NE, Op0, Op1);
   if (isMaxValueMinusOne(CI, false))  // A u MAX-1 - A == MAX
 return new ICmpInst(ICmpInst::ICMP_EQ, Op0, AddOne(CI));
+
+  // (x u 2147483647) - (x s 0)  - true if sign bit set
+  if (CI-isMaxValue(true))
+return new ICmpInst(ICmpInst::ICMP_SLT, Op0,
+ConstantInt::getNullValue(Op0-getType()));
   break;
 
 case ICmpInst::ICMP_SGT:
@@ -6559,15 +6569,15 @@
 // to an integer, then shift the bit to the appropriate place and then
 // cast to integer to avoid the comparison.
 if (ConstantInt *Op1C = dyn_castConstantInt(ICI-getOperand(1))) {
-  const APInt Op1CV = Op1C-getValue();
-  // cast (X == 0) to int -- X^1  iff X has only the low bit set.
-  // cast (X == 0) to int -- (X1)^1 iff X has only the 2nd bit set.
-  // cast (X == 1) to int -- Xiff X has only the low bit set.
-  // cast (X == 2) to int -- X1 iff X has only the 2nd bit set.
-  // cast (X != 0) to int -- Xiff X has only the low bit set.
-  // cast (X != 0) to int -- X1 iff X has only the 2nd bit set.
-  // cast (X != 1) to int -- X^1  iff X has only the low bit set.
-  // cast (X != 2) to int -- (X1)^1 iff X has only the 2nd bit set.
+  const APInt Op1CV = Op1C-getValue();
+  // zext (X == 0) to i32 -- X^1  iff X has only the low bit set.
+  // zext (X == 0) to i32 -- (X1)^1 iff X has only the 2nd bit set.
+  // zext (X == 1) to i32 -- Xiff X has only the low bit set.
+  // zext (X == 2) to i32 -- X1 iff X has only the 2nd bit set.
+  // zext (X != 0) to i32 -- Xiff X has only the low bit set.
+  // zext (X != 0) to i32 -- X1 iff X has only the 2nd bit set.
+  // zext (X != 1) to i32 -- X^1  iff X has only the low bit set.
+  // zext (X != 2) to i32 -- (X1)^1 iff X has only the 2nd bit set.
   if ((Op1CV == 0 || Op1CV.isPowerOf2())  
   // This only works for EQ and NE
   ICI-isEquality()) {
@@ -6617,7 +6627,13 @@
 }
 
 Instruction *InstCombiner::visitSExt(CastInst CI) {
-  return commonIntCastTransforms(CI);
+  if (Instruction *I = commonIntCastTransforms(CI))
+return I;
+  
+  // (x s 0) ? -1 : 0 - ashr x, 31
+  // (x u 2147483647) ? -1 : 0 - ashr x, 31
+
+  return 0;
 }
 
 Instruction *InstCombiner::visitFPTrunc(CastInst CI) {
@@ -6901,34 +6917,25 @@
   // Selecting between two integer constants?
   if (ConstantInt *TrueValC = dyn_castConstantInt(TrueVal))
 if (ConstantInt *FalseValC = dyn_castConstantInt(FalseVal)) {
-  // select C, 1, 0 - cast C to int
+  // select C, 1, 0 - zext C to int
   if (FalseValC-isZero()  TrueValC-getValue() == 1) {
 return CastInst::create(Instruction::ZExt, CondVal, SI.getType());
   } else if (TrueValC-isZero()  FalseValC-getValue() == 1) {
-// select C, 0, 1 - cast !C to int
+// select C, 0, 1 - zext !C to int
 Value *NotCond =
   InsertNewInstBefore(BinaryOperator::createNot(CondVal,
not.+CondVal-getName()), SI);
 return CastInst::create(Instruction::ZExt, NotCond, SI.getType());
   }
+  
+  // FIXME: Turn select 0/-1 and -1/0 into sext from condition!
 
   if (ICmpInst *IC = dyn_castICmpInst(SI.getCondition())) {
 
 // (x s 0) ? -1 : 0 - ashr x, 31
-// (x u 2147483647) ? -1 : 0 - ashr x, 31
 if (TrueValC-isAllOnesValue()  FalseValC-isZero())
   if (ConstantInt *CmpCst = dyn_castConstantInt(IC-getOperand(1))) {
-bool CanXForm = false;
-if (IC-isSignedPredicate())
-  CanXForm = 

[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-04-11 Thread Chris Lattner


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.740 - 1.741
---
Log message:

Simplify some comparisons to arithmetic, this implements:
Transforms/InstCombine/icmp.ll


---
Diffs of the changes:  (+27 -0)

 InstructionCombining.cpp |   27 +++
 1 files changed, 27 insertions(+)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.740 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.741
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.740   Wed Apr 11 
01:12:58 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Wed Apr 11 01:53:04 2007
@@ -6570,6 +6570,33 @@
 // cast to integer to avoid the comparison.
 if (ConstantInt *Op1C = dyn_castConstantInt(ICI-getOperand(1))) {
   const APInt Op1CV = Op1C-getValue();
+  
+  // zext (x s  0) to i32 -- xu31  true if signbit set.
+  // zext (x s -1) to i32 -- (xu31)^1  true if signbit clear.
+  if ((ICI-getPredicate() == ICmpInst::ICMP_SLT  Op1CV == 0) ||
+  (ICI-getPredicate() == ICmpInst::ICMP_SGT 
Op1CV.isAllOnesValue())){
+Value *In = ICI-getOperand(0);
+Value *Sh = ConstantInt::get(In-getType(),
+In-getType()-getPrimitiveSizeInBits()-1);
+In = InsertNewInstBefore(BinaryOperator::createLShr(In, Sh,
+
In-getName()+.lobit), 
+ CI);
+if (In-getType() != CI.getType())
+  In = CastInst::createIntegerCast(In, CI.getType(),
+   false/*ZExt*/, tmp, CI);
+
+if (ICI-getPredicate() == ICmpInst::ICMP_SGT) {
+  Constant *One = ConstantInt::get(In-getType(), 1);
+  In = InsertNewInstBefore(BinaryOperator::createXor(In, One,
+  
In-getName()+.not), 
+   CI);
+}
+
+return ReplaceInstUsesWith(CI, In);
+  }
+  
+  
+  
   // zext (X == 0) to i32 -- X^1  iff X has only the low bit set.
   // zext (X == 0) to i32 -- (X1)^1 iff X has only the 2nd bit set.
   // zext (X == 1) to i32 -- Xiff X has only the low bit set.



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-04-11 Thread Chris Lattner


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.741 - 1.742
---
Log message:

Turn stuff like:

icmp slt i32 %X, 0  ; i1:0 [#uses=1]
sext i1 %0 to i32   ; i32:1 [#uses=1]

into:

%X.lobit = ashr i32 %X, 31  ; i32 [#uses=1]

This implements InstCombine/icmp.ll:test[34]



---
Diffs of the changes:  (+40 -9)

 InstructionCombining.cpp |   49 ++-
 1 files changed, 40 insertions(+), 9 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.741 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.742
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.741   Wed Apr 11 
01:53:04 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Wed Apr 11 01:57:46 2007
@@ -193,9 +193,9 @@
  BinaryOperator I);
 Instruction *commonCastTransforms(CastInst CI);
 Instruction *commonIntCastTransforms(CastInst CI);
-Instruction *visitTrunc(CastInst CI);
-Instruction *visitZExt(CastInst CI);
-Instruction *visitSExt(CastInst CI);
+Instruction *visitTrunc(TruncInst CI);
+Instruction *visitZExt(ZExtInst CI);
+Instruction *visitSExt(SExtInst CI);
 Instruction *visitFPTrunc(CastInst CI);
 Instruction *visitFPExt(CastInst CI);
 Instruction *visitFPToUI(CastInst CI);
@@ -6471,7 +6471,7 @@
   return 0;
 }
 
-Instruction *InstCombiner::visitTrunc(CastInst CI) {
+Instruction *InstCombiner::visitTrunc(TruncInst CI) {
   if (Instruction *Result = commonIntCastTransforms(CI))
 return Result;
   
@@ -6528,7 +6528,7 @@
   return 0;
 }
 
-Instruction *InstCombiner::visitZExt(CastInst CI) {
+Instruction *InstCombiner::visitZExt(ZExtInst CI) {
   // If one of the common conversion will work ..
   if (Instruction *Result = commonIntCastTransforms(CI))
 return Result;
@@ -6653,13 +6653,44 @@
   return 0;
 }
 
-Instruction *InstCombiner::visitSExt(CastInst CI) {
+Instruction *InstCombiner::visitSExt(SExtInst CI) {
   if (Instruction *I = commonIntCastTransforms(CI))
 return I;
   
-  // (x s 0) ? -1 : 0 - ashr x, 31
-  // (x u 2147483647) ? -1 : 0 - ashr x, 31
-
+  Value *Src = CI.getOperand(0);
+  
+  // sext (x s 0) - ashr x, 31   - all ones if signed
+  // sext (x s -1) - ashr x, 31  - all ones if not signed
+  if (ICmpInst *ICI = dyn_castICmpInst(Src)) {
+// If we are just checking for a icmp eq of a single bit and zext'ing it
+// to an integer, then shift the bit to the appropriate place and then
+// cast to integer to avoid the comparison.
+if (ConstantInt *Op1C = dyn_castConstantInt(ICI-getOperand(1))) {
+  const APInt Op1CV = Op1C-getValue();
+  
+  // sext (x s  0) to i32 -- xs31  true if signbit set.
+  // sext (x s -1) to i32 -- (xs31)^-1  true if signbit clear.
+  if ((ICI-getPredicate() == ICmpInst::ICMP_SLT  Op1CV == 0) ||
+  (ICI-getPredicate() == ICmpInst::ICMP_SGT 
Op1CV.isAllOnesValue())){
+Value *In = ICI-getOperand(0);
+Value *Sh = ConstantInt::get(In-getType(),
+ 
In-getType()-getPrimitiveSizeInBits()-1);
+In = InsertNewInstBefore(BinaryOperator::createAShr(In, Sh,
+
In-getName()+.lobit), 
+ CI);
+if (In-getType() != CI.getType())
+  In = CastInst::createIntegerCast(In, CI.getType(),
+   true/*SExt*/, tmp, CI);
+
+if (ICI-getPredicate() == ICmpInst::ICMP_SGT)
+  In = InsertNewInstBefore(BinaryOperator::createNot(In,
+ In-getName()+.not), CI);
+
+return ReplaceInstUsesWith(CI, In);
+  }
+}
+  }
+  
   return 0;
 }
 



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-04-10 Thread Chris Lattner


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.738 - 1.739
---
Log message:

fix a miscompilation of:
define i32 @test(i32 %X) {
entry:
%Y = and i32 %X, 4  ; i32 [#uses=1]
icmp eq i32 %Y, 0   ; i1:0 [#uses=1]
sext i1 %0 to i32   ; i32:1 [#uses=1]
ret i32 %1
}

by moving code out of commonIntCastTransforms into visitZExt.  Simplify the
APInt gymnastics in it etc.



---
Diffs of the changes:  (+59 -63)

 InstructionCombining.cpp |  122 ++-
 1 files changed, 59 insertions(+), 63 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.738 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.739
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.738   Mon Apr  9 
18:52:13 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Wed Apr 11 00:45:39 2007
@@ -6457,69 +6457,6 @@
   }
 }
 break;
-
-  case Instruction::ICmp:
-// If we are just checking for a icmp eq of a single bit and casting it
-// to an integer, then shift the bit to the appropriate place and then
-// cast to integer to avoid the comparison.
-if (ConstantInt *Op1C = dyn_castConstantInt(Op1)) {
-  const APInt Op1CV = Op1C-getValue();
-  // cast (X == 0) to int -- X^1  iff X has only the low bit set.
-  // cast (X == 0) to int -- (X1)^1 iff X has only the 2nd bit set.
-  // cast (X == 1) to int -- Xiff X has only the low bit set.
-  // cast (X == 2) to int -- X1 iff X has only the 2nd bit set.
-  // cast (X != 0) to int -- Xiff X has only the low bit set.
-  // cast (X != 0) to int -- X1 iff X has only the 2nd bit set.
-  // cast (X != 1) to int -- X^1  iff X has only the low bit set.
-  // cast (X != 2) to int -- (X1)^1 iff X has only the 2nd bit set.
-  if (Op1CV == 0 || Op1CV.isPowerOf2()) {
-// If Op1C some other power of two, convert:
-uint32_t BitWidth = Op1C-getType()-getBitWidth();
-APInt KnownZero(BitWidth, 0), KnownOne(BitWidth, 0);
-APInt TypeMask(APInt::getAllOnesValue(BitWidth));
-ComputeMaskedBits(Op0, TypeMask, KnownZero, KnownOne);
-
-// This only works for EQ and NE
-ICmpInst::Predicate pred = castICmpInst(SrcI)-getPredicate();
-if (pred != ICmpInst::ICMP_NE  pred != ICmpInst::ICMP_EQ)
-  break;
-
-APInt KnownZeroMask(KnownZero ^ TypeMask);
-if (KnownZeroMask.isPowerOf2()) { // Exactly 1 possible 1?
-  bool isNE = pred == ICmpInst::ICMP_NE;
-  if (Op1CV != 0  (Op1CV != KnownZeroMask)) {
-// (X4) == 2 -- false
-// (X4) != 2 -- true
-Constant *Res = ConstantInt::get(Type::Int1Ty, isNE);
-Res = ConstantExpr::getZExt(Res, CI.getType());
-return ReplaceInstUsesWith(CI, Res);
-  }
-  
-  uint32_t ShiftAmt = KnownZeroMask.logBase2();
-  Value *In = Op0;
-  if (ShiftAmt) {
-// Perform a logical shr by shiftamt.
-// Insert the shift to put the result in the low bit.
-In = InsertNewInstBefore(
-  BinaryOperator::createLShr(In,
- ConstantInt::get(In-getType(), ShiftAmt),
- In-getName()+.lobit), CI);
-  }
-  
-  if ((Op1CV != 0) == isNE) { // Toggle the low bit.
-Constant *One = ConstantInt::get(In-getType(), 1);
-In = BinaryOperator::createXor(In, One, tmp);
-InsertNewInstBefore(castInstruction(In), CI);
-  }
-  
-  if (CI.getType() == In-getType())
-return ReplaceInstUsesWith(CI, In);
-  else
-return CastInst::createIntegerCast(In, CI.getType(), 
false/*ZExt*/);
-}
-  }
-}
-break;
   }
   return 0;
 }
@@ -6617,6 +6554,65 @@
 }
   }
 
+  if (ICmpInst *ICI = dyn_castICmpInst(Src)) {
+// If we are just checking for a icmp eq of a single bit and zext'ing it
+// to an integer, then shift the bit to the appropriate place and then
+// cast to integer to avoid the comparison.
+if (ConstantInt *Op1C = dyn_castConstantInt(ICI-getOperand(1))) {
+  const APInt Op1CV = Op1C-getValue();
+  // cast (X == 0) to int -- X^1  iff X has only the low bit set.
+  // cast (X == 0) to int -- (X1)^1 iff X has only the 2nd bit set.
+  // cast (X == 1) to int -- Xiff X has only the low bit set.
+  // cast (X == 2) to int -- X1 iff X has only the 2nd bit set.
+  // cast (X != 0) to int -- Xiff X has only the low bit set.
+  // cast (X != 0) to int -- X1 iff X has only the 2nd bit set.
+  // cast (X != 1) to int -- X^1  iff X has only the low bit set.
+  // cast (X != 2) to int -- 

[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-04-08 Thread Chris Lattner


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.732 - 1.733
---
Log message:

Generalize the code that handles (AB)|(AC) to work where B/C are not 
constants.
Add a new xform to simplify (AB)|(~AC).  THis implements 
InstCombine/or2.ll:test1



---
Diffs of the changes:  (+83 -30)

 InstructionCombining.cpp |  113 ++-
 1 files changed, 83 insertions(+), 30 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.732 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.733
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.732   Fri Apr  6 
13:57:34 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Sun Apr  8 02:47:01 2007
@@ -3709,36 +3709,89 @@
 return BinaryOperator::createXor(NOr, C1);
   }
 
-  // (A  C1)|(B  C2)
-  if (match(Op0, m_And(m_Value(A), m_ConstantInt(C1))) 
-  match(Op1, m_And(m_Value(B), m_ConstantInt(C2 {
-
-if (A == B)  // (A  C1)|(A  C2) == A  (C1|C2)
-  return BinaryOperator::createAnd(A, 
- ConstantInt::get(C1-getValue() | C2-getValue()));
-
-
-// If we have: ((V + N)  C1) | (V  C2)
-// .. and C2 = ~C1 and C2 is 0+1+ and (N  C2) == 0
-// replace with V+N.
-if (C1-getValue() == ~C2-getValue()) {
-  Value *V1 = 0, *V2 = 0;
-  if ((C2-getValue()  (C2-getValue()+1)) == 0  // C2 == 0+1+
-  match(A, m_Add(m_Value(V1), m_Value(V2 {
-// Add commutes, try both ways.
-if (V1 == B  MaskedValueIsZero(V2, C2-getValue()))
-  return ReplaceInstUsesWith(I, A);
-if (V2 == B  MaskedValueIsZero(V1, C2-getValue()))
-  return ReplaceInstUsesWith(I, A);
-  }
-  // Or commutes, try both ways.
-  if ((C1-getValue()  (C1-getValue()+1)) == 0 
-  match(B, m_Add(m_Value(V1), m_Value(V2 {
-// Add commutes, try both ways.
-if (V1 == A  MaskedValueIsZero(V2, C1-getValue()))
-  return ReplaceInstUsesWith(I, B);
-if (V2 == A  MaskedValueIsZero(V1, C1-getValue()))
-  return ReplaceInstUsesWith(I, B);
+  // (A  C)|(B  D)
+  Value *C, *D;
+  if (match(Op0, m_And(m_Value(A), m_Value(C))) 
+  match(Op1, m_And(m_Value(B), m_Value(D {
+
+// Check to see if we have any common things being and'ed.  If so, find the
+// terms for V1  (V2|V3).
+Value *V1 = 0, *V2 = 0, *V3 = 0;
+if (isOnlyUse(Op0) || isOnlyUse(Op1)) {
+  if (A == B)  // (A  C)|(A  D) == A  (C|D)
+V1 = A, V2 = C, V3 = D;
+  else if (A == D) // (A  C)|(B  A) == A  (B|C)
+V1 = A, V2 = B, V3 = C;
+  else if (C == B) // (A  C)|(C  D) == C  (A|D)
+V1 = C, V2 = A, V3 = D;
+  else if (C == D) // (A  C)|(B  C) == C  (A|B)
+V1 = C, V2 = A, V3 = B;
+  
+  if (V1) {
+Value *Or =
+  InsertNewInstBefore(BinaryOperator::createOr(V2, V3, tmp), I);
+return BinaryOperator::createAnd(V1, Or);
+  }
+  
+  // (V1  V3)|(V2  ~V3) - ((V1 ^ V2)  V3) ^ V2
+  if (isOnlyUse(Op0)  isOnlyUse(Op1)) {
+// Try all combination of terms to find V3 and ~V3.
+if (A-hasOneUse()  match(A, m_Not(m_Value(V3 {
+  if (V3 == B)
+V1 = D, V2 = C;
+  else if (V3 == D)
+V1 = B, V2 = C;
+}
+if (B-hasOneUse()  match(B, m_Not(m_Value(V3 {
+  if (V3 == A)
+V1 = C, V2 = D;
+  else if (V3 == C)
+V1 = A, V2 = D;
+}
+if (C-hasOneUse()  match(C, m_Not(m_Value(V3 {
+  if (V3 == B)
+V1 = D, V2 = A;
+  else if (V3 == D)
+V1 = B, V2 = A;
+}
+if (D-hasOneUse()  match(D, m_Not(m_Value(V3 {
+  if (V3 == A)
+V1 = C, V2 = B;
+  else if (V3 == C)
+V1 = A, V2 = B;
+}
+if (V1) {
+  A = InsertNewInstBefore(BinaryOperator::createXor(V1, V2, tmp), I);
+  A = InsertNewInstBefore(BinaryOperator::createAnd(A, V3, tmp), I);
+  return BinaryOperator::createXor(A, V2);
+}
+  }
+}
+
+C1 = dyn_castConstantInt(C);
+C2 = dyn_castConstantInt(D);
+if (C1  C2) {  // (A  C1)|(B  C2)
+  // If we have: ((V + N)  C1) | (V  C2)
+  // .. and C2 = ~C1 and C2 is 0+1+ and (N  C2) == 0
+  // replace with V+N.
+  if (C1-getValue() == ~C2-getValue()) {
+if ((C2-getValue()  (C2-getValue()+1)) == 0  // C2 == 0+1+
+match(A, m_Add(m_Value(V1), m_Value(V2 {
+  // Add commutes, try both ways.
+  if (V1 == B  MaskedValueIsZero(V2, C2-getValue()))
+return ReplaceInstUsesWith(I, A);
+  if (V2 == B  MaskedValueIsZero(V1, C2-getValue()))
+return ReplaceInstUsesWith(I, A);
+}
+// Or commutes, try both ways.
+if ((C1-getValue()  (C1-getValue()+1)) == 0 
+match(B, 

[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-04-08 Thread Chris Lattner


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.733 - 1.734
---
Log message:

Fix regression on Instcombine/apint-or2.ll 


---
Diffs of the changes:  (+29 -30)

 InstructionCombining.cpp |   59 +++
 1 files changed, 29 insertions(+), 30 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.733 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.734
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.733   Sun Apr  8 
02:47:01 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Sun Apr  8 02:55:22 2007
@@ -3713,10 +3713,36 @@
   Value *C, *D;
   if (match(Op0, m_And(m_Value(A), m_Value(C))) 
   match(Op1, m_And(m_Value(B), m_Value(D {
-
+Value *V1 = 0, *V2 = 0, *V3 = 0;
+C1 = dyn_castConstantInt(C);
+C2 = dyn_castConstantInt(D);
+if (C1  C2) {  // (A  C1)|(B  C2)
+  // If we have: ((V + N)  C1) | (V  C2)
+  // .. and C2 = ~C1 and C2 is 0+1+ and (N  C2) == 0
+  // replace with V+N.
+  if (C1-getValue() == ~C2-getValue()) {
+if ((C2-getValue()  (C2-getValue()+1)) == 0  // C2 == 0+1+
+match(A, m_Add(m_Value(V1), m_Value(V2 {
+  // Add commutes, try both ways.
+  if (V1 == B  MaskedValueIsZero(V2, C2-getValue()))
+return ReplaceInstUsesWith(I, A);
+  if (V2 == B  MaskedValueIsZero(V1, C2-getValue()))
+return ReplaceInstUsesWith(I, A);
+}
+// Or commutes, try both ways.
+if ((C1-getValue()  (C1-getValue()+1)) == 0 
+match(B, m_Add(m_Value(V1), m_Value(V2 {
+  // Add commutes, try both ways.
+  if (V1 == A  MaskedValueIsZero(V2, C1-getValue()))
+return ReplaceInstUsesWith(I, B);
+  if (V2 == A  MaskedValueIsZero(V1, C1-getValue()))
+return ReplaceInstUsesWith(I, B);
+}
+  }
+}
+
 // Check to see if we have any common things being and'ed.  If so, find the
 // terms for V1  (V2|V3).
-Value *V1 = 0, *V2 = 0, *V3 = 0;
 if (isOnlyUse(Op0) || isOnlyUse(Op1)) {
   if (A == B)  // (A  C)|(A  D) == A  (C|D)
 V1 = A, V2 = C, V3 = D;
@@ -3734,7 +3760,7 @@
   }
   
   // (V1  V3)|(V2  ~V3) - ((V1 ^ V2)  V3) ^ V2
-  if (isOnlyUse(Op0)  isOnlyUse(Op1)) {
+  if (0  isOnlyUse(Op0)  isOnlyUse(Op1)) {
 // Try all combination of terms to find V3 and ~V3.
 if (A-hasOneUse()  match(A, m_Not(m_Value(V3 {
   if (V3 == B)
@@ -3767,33 +3793,6 @@
 }
   }
 }
-
-C1 = dyn_castConstantInt(C);
-C2 = dyn_castConstantInt(D);
-if (C1  C2) {  // (A  C1)|(B  C2)
-  // If we have: ((V + N)  C1) | (V  C2)
-  // .. and C2 = ~C1 and C2 is 0+1+ and (N  C2) == 0
-  // replace with V+N.
-  if (C1-getValue() == ~C2-getValue()) {
-if ((C2-getValue()  (C2-getValue()+1)) == 0  // C2 == 0+1+
-match(A, m_Add(m_Value(V1), m_Value(V2 {
-  // Add commutes, try both ways.
-  if (V1 == B  MaskedValueIsZero(V2, C2-getValue()))
-return ReplaceInstUsesWith(I, A);
-  if (V2 == B  MaskedValueIsZero(V1, C2-getValue()))
-return ReplaceInstUsesWith(I, A);
-}
-// Or commutes, try both ways.
-if ((C1-getValue()  (C1-getValue()+1)) == 0 
-match(B, m_Add(m_Value(V1), m_Value(V2 {
-  // Add commutes, try both ways.
-  if (V1 == A  MaskedValueIsZero(V2, C1-getValue()))
-return ReplaceInstUsesWith(I, B);
-  if (V2 == A  MaskedValueIsZero(V1, C1-getValue()))
-return ReplaceInstUsesWith(I, B);
-}
-  }
-}
   }
   
   // (X  Z) | (Y  Z)  - (X|Y)  Z  for all shifts.



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-04-08 Thread Chris Lattner


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.734 - 1.735
---
Log message:

reenable this xform, whoops :)


---
Diffs of the changes:  (+2 -1)

 InstructionCombining.cpp |3 ++-
 1 files changed, 2 insertions(+), 1 deletion(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.734 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.735
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.734   Sun Apr  8 
02:55:22 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Sun Apr  8 03:01:49 2007
@@ -3739,6 +3739,7 @@
 return ReplaceInstUsesWith(I, B);
 }
   }
+  V1 = 0; V2 = 0; V3 = 0;
 }
 
 // Check to see if we have any common things being and'ed.  If so, find the
@@ -3760,7 +3761,7 @@
   }
   
   // (V1  V3)|(V2  ~V3) - ((V1 ^ V2)  V3) ^ V2
-  if (0  isOnlyUse(Op0)  isOnlyUse(Op1)) {
+  if (isOnlyUse(Op0)  isOnlyUse(Op1)) {
 // Try all combination of terms to find V3 and ~V3.
 if (A-hasOneUse()  match(A, m_Not(m_Value(V3 {
   if (V3 == B)



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-04-08 Thread Chris Lattner


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.735 - 1.736
---
Log message:

Eliminate useless insertelement instructions.  This implements
Transforms/InstCombine/vec_insertelt.ll and fixes PR1286: 
http://llvm.org/PR1286 .

We now compile the code from that bug into:

_foo:
movl 4(%esp), %eax
movdqa (%eax), %xmm0
movl 8(%esp), %ecx
psllw (%ecx), %xmm0
movdqa %xmm0, (%eax)
ret

instead of:

_foo:
subl $4, %esp
movl %ebp, (%esp)
movl %esp, %ebp
movl 12(%ebp), %eax
movdqa (%eax), %xmm0
#IMPLICIT_DEF %eax
pinsrw $2, %eax, %xmm0
xorl %ecx, %ecx
pinsrw $3, %ecx, %xmm0
pinsrw $4, %eax, %xmm0
pinsrw $5, %ecx, %xmm0
pinsrw $6, %eax, %xmm0
pinsrw $7, %ecx, %xmm0
movl 8(%ebp), %eax
movdqa (%eax), %xmm1
psllw %xmm0, %xmm1
movdqa %xmm1, (%eax)
movl %ebp, %esp
popl %ebp
ret

woo :)



---
Diffs of the changes:  (+4 -0)

 InstructionCombining.cpp |4 
 1 files changed, 4 insertions(+)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.735 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.736
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.735   Sun Apr  8 
03:01:49 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Sun Apr  8 20:11:16 2007
@@ -9160,6 +9160,10 @@
   Value *ScalarOp = IE.getOperand(1);
   Value *IdxOp= IE.getOperand(2);
   
+  // Inserting an undef or into an undefined place, remove this.
+  if (isaUndefValue(ScalarOp) || isaUndefValue(IdxOp))
+ReplaceInstUsesWith(IE, VecOp);
+  
   // If the inserted element was extracted from some other vector, and if the 
   // indexes are constant, try to turn this into a shufflevector operation.
   if (ExtractElementInst *EI = dyn_castExtractElementInst(ScalarOp)) {



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-04-08 Thread Chris Lattner


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.736 - 1.737
---
Log message:

Fix PR1304: http://llvm.org/PR1304  and 
Transforms/InstCombine/2007-04-08-SingleEltVectorCrash.ll


---
Diffs of the changes:  (+10 -2)

 InstructionCombining.cpp |   12 ++--
 1 files changed, 10 insertions(+), 2 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.736 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.737
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.736   Sun Apr  8 
20:11:16 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Sun Apr  8 20:37:55 2007
@@ -8943,11 +8943,19 @@
   // If extracting a specified index from the vector, see if we can recursively
   // find a previously computed scalar that was inserted into the vector.
   if (ConstantInt *IdxC = dyn_castConstantInt(EI.getOperand(1))) {
+unsigned IndexVal = IdxC-getZExtValue();
+unsigned VectorWidth = 
+  castVectorType(EI.getOperand(0)-getType())-getNumElements();
+  
+// If this is extracting an invalid index, turn this into undef, to avoid
+// crashing the code below.
+if (IndexVal = VectorWidth)
+  return ReplaceInstUsesWith(EI, UndefValue::get(EI.getType()));
+
 // This instruction only demands the single element from the input vector.
 // If the input vector has a single use, simplify it based on this use
 // property.
-uint64_t IndexVal = IdxC-getZExtValue();
-if (EI.getOperand(0)-hasOneUse()) {
+if (EI.getOperand(0)-hasOneUse()  VectorWidth != 1) {
   uint64_t UndefElts;
   if (Value *V = SimplifyDemandedVectorElts(EI.getOperand(0),
 1  IndexVal,



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-04-04 Thread Duncan Sands


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.728 - 1.729
---
Log message:

Fix comment.


---
Diffs of the changes:  (+1 -1)

 InstructionCombining.cpp |2 +-
 1 files changed, 1 insertion(+), 1 deletion(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.728 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.729
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.728   Tue Apr  3 
18:29:39 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Wed Apr  4 01:42:45 2007
@@ -4903,7 +4903,7 @@
   const APInt RHSV = RHS-getValue();
   
   switch (LHSI-getOpcode()) {
-  case Instruction::Xor: // (icmp pred (and X, XorCST), CI)
+  case Instruction::Xor: // (icmp pred (xor X, XorCST), CI)
 if (ConstantInt *XorCST = dyn_castConstantInt(LHSI-getOperand(1))) {
   // If this is a comparison that tests the signbit (X  0) or (x  -1),
   // fold the xor.



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-04-04 Thread Dale Johannesen


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.730 - 1.731
---
Log message:

Prevent transformConstExprCastCall from generating conversions that assert
elsewhere.


---
Diffs of the changes:  (+35 -0)

 InstructionCombining.cpp |   35 +++
 1 files changed, 35 insertions(+)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.730 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.731
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.730   Wed Apr  4 
11:58:57 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Wed Apr  4 14:16:42 2007
@@ -7469,6 +7469,7 @@
 const Type *ParamTy = FT-getParamType(i);
 const Type *ActTy = (*AI)-getType();
 ConstantInt *c = dyn_castConstantInt(*AI);
+//Some conversions are safe even if we do not have a body.
 //Either we can cast directly, or we can upconvert the argument
 bool isConvertible = ActTy == ParamTy ||
   (isaPointerType(ParamTy)  isaPointerType(ActTy)) ||
@@ -7477,6 +7478,40 @@
   (c  ParamTy-getPrimitiveSizeInBits() = 
ActTy-getPrimitiveSizeInBits()
 c-getValue().isStrictlyPositive());
 if (Callee-isDeclaration()  !isConvertible) return false;
+
+// Most other conversions can be done if we have a body, even if these
+// lose information, e.g. int-short.
+// Some conversions cannot be done at all, e.g. float to pointer.
+// Logic here parallels CastInst::getCastOpcode (the design there
+// requires legality checks like this be done before calling it).
+if (ParamTy-isInteger()) {
+  if (const VectorType *VActTy = dyn_castVectorType(ActTy)) {
+if (VActTy-getBitWidth() != ParamTy-getPrimitiveSizeInBits())
+  return false;
+  }
+  if (!ActTy-isInteger()  !ActTy-isFloatingPoint() 
+  !isaPointerType(ActTy))
+return false;
+} else if (ParamTy-isFloatingPoint()) {
+  if (const VectorType *VActTy = dyn_castVectorType(ActTy)) {
+if (VActTy-getBitWidth() != ParamTy-getPrimitiveSizeInBits())
+  return false;
+  }
+  if (!ActTy-isInteger()  !ActTy-isFloatingPoint())
+return false;
+} else if (const VectorType *VParamTy = dyn_castVectorType(ParamTy)) {
+  if (const VectorType *VActTy = dyn_castVectorType(ActTy)) {
+if (VActTy-getBitWidth() != VParamTy-getBitWidth())
+  return false;
+  }
+  if (VParamTy-getBitWidth() != ActTy-getPrimitiveSizeInBits())  
+return false;
+} else if (isaPointerType(ParamTy)) {
+  if (!ActTy-isInteger()  !isaPointerType(ActTy))
+return false;
+} else {
+  return false;
+}
   }
 
   if (FT-getNumParams()  NumActualArgs  !FT-isVarArg() 



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-04-03 Thread Evan Cheng


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.725 - 1.726
---
Log message:

Reverting back to 1.723. The last two commits broke JM (and possibily others) 
on ARM.

---
Diffs of the changes:  (+491 -524)

 InstructionCombining.cpp | 1015 ++-
 1 files changed, 491 insertions(+), 524 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.725 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.726
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.725   Mon Apr  2 
23:46:52 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Tue Apr  3 03:11:50 2007
@@ -183,9 +183,6 @@
 Instruction *visitFCmpInst(FCmpInst I);
 Instruction *visitICmpInst(ICmpInst I);
 Instruction *visitICmpInstWithCastAndCast(ICmpInst ICI);
-Instruction *visitICmpInstWithInstAndIntCst(ICmpInst ICI,
-Instruction *LHS,
-ConstantInt *RHS);
 
 Instruction *FoldGEPICmp(User *GEPLHS, Value *RHS,
  ICmpInst::Predicate Cond, Instruction I);
@@ -4716,11 +4713,496 @@
 // instruction, see if that instruction also has constants so that the 
 // instruction can be folded into the icmp 
 if (Instruction *LHSI = dyn_castInstruction(Op0))
-  if (Instruction *Res = visitICmpInstWithInstAndIntCst(I, LHSI, CI))
-return Res;
+  switch (LHSI-getOpcode()) {
+  case Instruction::And:
+if (LHSI-hasOneUse()  isaConstantInt(LHSI-getOperand(1)) 
+LHSI-getOperand(0)-hasOneUse()) {
+  ConstantInt *AndCST = castConstantInt(LHSI-getOperand(1));
+
+  // If the LHS is an AND of a truncating cast, we can widen the
+  // and/compare to be the input width without changing the value
+  // produced, eliminating a cast.
+  if (CastInst *Cast = dyn_castCastInst(LHSI-getOperand(0))) {
+// We can do this transformation if either the AND constant does 
not
+// have its sign bit set or if it is an equality comparison. 
+// Extending a relational comparison when we're checking the sign
+// bit would not work.
+if (Cast-hasOneUse()  isaTruncInst(Cast) 
+(I.isEquality() || AndCST-getValue().isPositive()  
+ CI-getValue().isPositive())) {
+  ConstantInt *NewCST;
+  ConstantInt *NewCI;
+  APInt NewCSTVal(AndCST-getValue()), NewCIVal(CI-getValue());
+  uint32_t BitWidth = castIntegerType(
+Cast-getOperand(0)-getType())-getBitWidth();
+  NewCST = ConstantInt::get(NewCSTVal.zext(BitWidth));
+  NewCI = ConstantInt::get(NewCIVal.zext(BitWidth));
+  Instruction *NewAnd = 
+BinaryOperator::createAnd(Cast-getOperand(0), NewCST, 
+  LHSI-getName());
+  InsertNewInstBefore(NewAnd, I);
+  return new ICmpInst(I.getPredicate(), NewAnd, NewCI);
+}
+  }
+  
+  // If this is: (X  C1)  C2 != C3 (where any shift and any compare
+  // could exist), turn it into (X  (C2  C1)) != (C3  C1).  This
+  // happens a LOT in code produced by the C front-end, for bitfield
+  // access.
+  BinaryOperator *Shift = 
dyn_castBinaryOperator(LHSI-getOperand(0));
+  if (Shift  !Shift-isShift())
+Shift = 0;
+
+  ConstantInt *ShAmt;
+  ShAmt = Shift ? dyn_castConstantInt(Shift-getOperand(1)) : 0;
+  const Type *Ty = Shift ? Shift-getType() : 0;  // Type of the shift.
+  const Type *AndTy = AndCST-getType();  // Type of the and.
+
+  // We can fold this as long as we can't shift unknown bits
+  // into the mask.  This can only happen with signed shift
+  // rights, as they sign-extend.
+  if (ShAmt) {
+bool CanFold = Shift-isLogicalShift();
+if (!CanFold) {
+  // To test for the bad case of the signed shr, see if any
+  // of the bits shifted in could be tested after the mask.
+  uint32_t TyBits = Ty-getPrimitiveSizeInBits();
+  int ShAmtVal = TyBits - ShAmt-getLimitedValue(TyBits);
+
+  uint32_t BitWidth = AndTy-getPrimitiveSizeInBits();
+  if ((APInt::getHighBitsSet(BitWidth, BitWidth-ShAmtVal)  
+   AndCST-getValue()) == 0)
+CanFold = true;
+}
+
+if (CanFold) {
+  Constant *NewCst;
+  if (Shift-getOpcode() == Instruction::Shl)
+NewCst = ConstantExpr::getLShr(CI, ShAmt);
+  else
+NewCst = ConstantExpr::getShl(CI, ShAmt);
+
+  // Check to see if we are shifting 

Re: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-04-03 Thread Anton Korobeynikov
 Reverting back to 1.723. The last two commits broke JM (and possibily others) 
 on ARM.
Definitely. Qt is broken too. Funny, but I see exactly the same errors,
as soon after Reid's InstCombine APIntifiaction (some bits are missing,
so tool outputs settitle instead of setTitle :) ). Will investigate
this evening. Seems to be easy to reduce to one file.

-- 
With best regards, Anton Korobeynikov.

Faculty of Mathematics  Mechanics, Saint Petersburg State University.


___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-04-03 Thread Chris Lattner


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.727 - 1.728
---
Log message:

Fix a bug I introduced with my patch yesterday which broke Qt (I converted
some constant exprs to apints).

Thanks to Anton for tracking down a small testcase that triggered this!



---
Diffs of the changes:  (+1 -1)

 InstructionCombining.cpp |2 +-
 1 files changed, 1 insertion(+), 1 deletion(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.727 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.728
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.727   Tue Apr  3 
12:43:25 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Tue Apr  3 18:29:39 2007
@@ -5087,7 +5087,7 @@
   Mask, LHSI-getName()+.mask);
   Value *And = InsertNewInstBefore(AndI, ICI);
   return new ICmpInst(ICI.getPredicate(), And,
-  ConstantInt::get(RHSV  ShAmtVal));
+  ConstantInt::get(RHSV.lshr(ShAmtVal)));
 }
   }
 }



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-04-02 Thread Zhou Sheng


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.721 - 1.722
---
Log message:

Use uint32_t for bitwidth instead of unsigned.


---
Diffs of the changes:  (+29 -29)

 InstructionCombining.cpp |   58 +++
 1 files changed, 29 insertions(+), 29 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.721 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.722
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.721   Mon Apr  2 
00:48:58 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Mon Apr  2 03:20:41 2007
@@ -1279,7 +1279,7 @@
 if (DemandedMask[BitWidth-1] == 0) {
   // Right fill the mask of bits for this SUB to demand the most
   // significant bit and all those below it.
-  unsigned NLZ = DemandedMask.countLeadingZeros();
+  uint32_t NLZ = DemandedMask.countLeadingZeros();
   APInt DemandedFromOps(APInt::getLowBitsSet(BitWidth, BitWidth-NLZ));
   if (SimplifyDemandedBits(I-getOperand(0), DemandedFromOps,
LHSKnownZero, LHSKnownOne, Depth+1))
@@ -1871,7 +1871,7 @@
 if (ConstantInt *CI = dyn_castConstantInt(RHSC)) {
   // X + (signbit) -- X ^ signbit
   const APInt Val = CI-getValue();
-  unsigned BitWidth = Val.getBitWidth();
+  uint32_t BitWidth = Val.getBitWidth();
   if (Val == APInt::getSignBit(BitWidth))
 return BinaryOperator::createXor(LHS, RHS);
   
@@ -1893,10 +1893,10 @@
 Value *XorLHS = 0;
 if (isaConstantInt(RHSC) 
 match(LHS, m_Xor(m_Value(XorLHS), m_ConstantInt(XorRHS {
-  unsigned TySizeBits = I.getType()-getPrimitiveSizeInBits();
+  uint32_t TySizeBits = I.getType()-getPrimitiveSizeInBits();
   const APInt RHSVal = castConstantInt(RHSC)-getValue();
   
-  unsigned Size = TySizeBits / 2;
+  uint32_t Size = TySizeBits / 2;
   APInt C0080Val(APInt(TySizeBits, 1ULL).shl(Size - 1));
   APInt CFF80Val(-C0080Val);
   do {
@@ -2049,7 +2049,7 @@
 // isSignBit - Return true if the value represented by the constant only has 
the
 // highest order bit set.
 static bool isSignBit(ConstantInt *CI) {
-  unsigned NumBits = CI-getType()-getPrimitiveSizeInBits();
+  uint32_t NumBits = CI-getType()-getPrimitiveSizeInBits();
   return CI-getValue() == APInt::getSignBit(NumBits);
 }
 
@@ -2321,8 +2321,8 @@
 // If the multiply type is not the same as the source type, sign extend
 // or truncate to the multiply type.
 if (I.getType() != V-getType()) {
-  unsigned SrcBits = V-getType()-getPrimitiveSizeInBits();
-  unsigned DstBits = I.getType()-getPrimitiveSizeInBits();
+  uint32_t SrcBits = V-getType()-getPrimitiveSizeInBits();
+  uint32_t DstBits = I.getType()-getPrimitiveSizeInBits();
   Instruction::CastOps opcode = 
 (SrcBits == DstBits ? Instruction::BitCast : 
  (SrcBits  DstBits ? Instruction::SExt : Instruction::Trunc));
@@ -3081,7 +3081,7 @@
 // any number of 0s on either side.  The 1s are allowed to wrap from LSB to
 // MSB, so 0x000FFF0, 0x, and 0xFFFF are all runs.  0x0F0F is
 // not, since all 1s are not contiguous.
-static bool isRunOfOnes(ConstantInt *Val, unsigned MB, unsigned ME) {
+static bool isRunOfOnes(ConstantInt *Val, uint32_t MB, uint32_t ME) {
   const APInt V = Val-getValue();
   uint32_t BitWidth = Val-getType()-getBitWidth();
   if (!APIntOps::isShiftedMask(BitWidth, V)) return false;
@@ -3125,7 +3125,7 @@
   // Otherwise, if Mask is 0+1+0+, and if B is known to have the low 0+
   // part, we don't need any explicit masks to take them out of A.  If that
   // is all N is, ignore it.
-  unsigned MB = 0, ME = 0;
+  uint32_t MB = 0, ME = 0;
   if (isRunOfOnes(Mask, MB, ME)) {  // begin/end bit of run, inclusive
 uint32_t BitWidth = castIntegerType(RHS-getType())-getBitWidth();
 APInt Mask(APInt::getLowBitsSet(BitWidth, MB-1));
@@ -4844,7 +4844,7 @@
   case Instruction::Shl: // (icmp pred (shl X, ShAmt), CI)
 if (ConstantInt *ShAmt = dyn_castConstantInt(LHSI-getOperand(1))) {
   if (I.isEquality()) {
-unsigned TypeBits = CI-getType()-getPrimitiveSizeInBits();
+uint32_t TypeBits = CI-getType()-getPrimitiveSizeInBits();
 
 // Check that the shift amount is in range.  If not, don't perform
 // undefined shifts.  When the shift is visited it will be
@@ -4865,8 +4865,8 @@
 if (LHSI-hasOneUse()) {
   // Otherwise strength reduce the shift into an and.
   uint32_t ShAmtVal = (uint32_t)ShAmt-getLimitedValue(TypeBits);
-  uint64_t Val = (1ULL  (TypeBits-ShAmtVal))-1;
-  Constant *Mask = ConstantInt::get(CI-getType(), Val);
+  Constant *Mask = ConstantInt::get(
+

[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-04-02 Thread Zhou Sheng


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.722 - 1.723
---
Log message:

1. Make use of APInt operation instead of using ConstantExpr::getXXX.
2. Use cheaper APInt methods.


---
Diffs of the changes:  (+19 -26)

 InstructionCombining.cpp |   45 +++--
 1 files changed, 19 insertions(+), 26 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.722 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.723
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.722   Mon Apr  2 
03:20:41 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Mon Apr  2 08:45:30 2007
@@ -522,7 +522,7 @@
 
   // Constants can be considered to be not'ed values...
   if (ConstantInt *C = dyn_castConstantInt(V))
-return ConstantExpr::getNot(C);
+return ConstantInt::get(~C-getValue());
   return 0;
 }
 
@@ -844,16 +844,14 @@
  Ty, KnownZero, KnownOne and Min, Max must have equal bitwidth.);
   APInt UnknownBits = ~(KnownZero|KnownOne);
 
-  APInt SignBit(APInt::getSignBit(BitWidth));
-  
   // The minimum value is when all unknown bits are zeros, EXCEPT for the sign
   // bit if it is unknown.
   Min = KnownOne;
   Max = KnownOne|UnknownBits;
   
   if (UnknownBits[BitWidth-1]) { // Sign bit is unknown
-Min |= SignBit;
-Max = ~SignBit;
+Min.set(BitWidth-1);
+Max.clear(BitWidth-1);
   }
 }
 
@@ -1133,7 +1131,6 @@
 const IntegerType *SrcTy = castIntegerType(I-getOperand(0)-getType());
 uint32_t SrcBitWidth = SrcTy-getBitWidth();
 
-DemandedMask = SrcTy-getMask().zext(BitWidth);
 DemandedMask.trunc(SrcBitWidth);
 RHSKnownZero.trunc(SrcBitWidth);
 RHSKnownOne.trunc(SrcBitWidth);
@@ -1154,9 +1151,6 @@
 const IntegerType *SrcTy = castIntegerType(I-getOperand(0)-getType());
 uint32_t SrcBitWidth = SrcTy-getBitWidth();
 
-// Get the sign bit for the source type
-APInt InSignBit(APInt::getSignBit(SrcBitWidth));
-InSignBit.zext(BitWidth);
 APInt InputDemandedBits = DemandedMask  
   APInt::getLowBitsSet(BitWidth, SrcBitWidth);
 
@@ -1164,7 +1158,7 @@
 // If any of the sign extended bits are demanded, we know that the sign
 // bit is demanded.
 if ((NewBits  DemandedMask) != 0)
-  InputDemandedBits |= InSignBit;
+  InputDemandedBits.set(SrcBitWidth-1);
   
 InputDemandedBits.trunc(SrcBitWidth);
 RHSKnownZero.trunc(SrcBitWidth);
@@ -3652,7 +3646,8 @@
   Instruction *Or = BinaryOperator::createOr(X, RHS);
   InsertNewInstBefore(Or, I);
   Or-takeName(Op0);
-  return BinaryOperator::createAnd(Or, ConstantExpr::getOr(RHS, C1));
+  return BinaryOperator::createAnd(Or, 
+   ConstantInt::get(RHS-getValue() | C1-getValue()));
 }
 
 // (X ^ C1) | C2 -- (X | C2) ^ (C1~C2)
@@ -3661,7 +3656,7 @@
   InsertNewInstBefore(Or, I);
   Or-takeName(Op0);
   return BinaryOperator::createXor(Or,
- ConstantExpr::getAnd(C1, ConstantExpr::getNot(RHS)));
+ ConstantInt::get(C1-getValue()  ~RHS-getValue()));
 }
 
 // Try to fold constant and into select arguments.
@@ -3716,13 +3711,14 @@
   match(Op1, m_And(m_Value(B), m_ConstantInt(C2 {
 
 if (A == B)  // (A  C1)|(A  C2) == A  (C1|C2)
-  return BinaryOperator::createAnd(A, ConstantExpr::getOr(C1, C2));
+  return BinaryOperator::createAnd(A, 
+ ConstantInt::get(C1-getValue() | C2-getValue()));
 
 
 // If we have: ((V + N)  C1) | (V  C2)
 // .. and C2 = ~C1 and C2 is 0+1+ and (N  C2) == 0
 // replace with V+N.
-if (C1 == ConstantExpr::getNot(C2)) {
+if (C1-getValue() == ~C2-getValue()) {
   Value *V1 = 0, *V2 = 0;
   if ((C2-getValue()  (C2-getValue()+1)) == 0  // C2 == 0+1+
   match(A, m_Add(m_Value(V1), m_Value(V2 {
@@ -3826,7 +3822,7 @@
 Instruction *Add = BinaryOperator::createAdd(LHSVal, AddCST,
   
LHSVal-getName()+.off);
 InsertNewInstBefore(Add, I);
-AddCST = ConstantExpr::getSub(AddOne(RHSCst), LHSCst);
+AddCST = Subtract(AddOne(RHSCst), LHSCst);
 return new ICmpInst(ICmpInst::ICMP_ULT, Add, AddCST);
   }
   break; // (X == 13 | X == 15) - no 
change
@@ -4027,7 +4023,7 @@
 Constant *NewRHS = ConstantExpr::getOr(Op0CI, RHS);
 // Anything in both C1 and C2 is known to be zero, remove it from
 // NewRHS.
-Constant *CommonBits = ConstantExpr::getAnd(Op0CI, RHS);
+Constant *CommonBits = And(Op0CI, RHS);
 NewRHS = ConstantExpr::getAnd(NewRHS, 
   ConstantExpr::getNot(CommonBits));
 AddToWorkList(Op0I);
@@ -4196,7 +4192,7 @@
 /// 

[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-04-02 Thread Chris Lattner


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.723 - 1.724
---
Log message:

Fix PR1253: http://llvm.org/PR1253  and xor2.ll:test[01]



---
Diffs of the changes:  (+30 -1)

 InstructionCombining.cpp |   31 ++-
 1 files changed, 30 insertions(+), 1 deletion(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.723 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.724
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.723   Mon Apr  2 
08:45:30 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Mon Apr  2 20:47:41 2007
@@ -4714,7 +4714,36 @@
 // instruction can be folded into the icmp 
 if (Instruction *LHSI = dyn_castInstruction(Op0))
   switch (LHSI-getOpcode()) {
-  case Instruction::And:
+  case Instruction::Xor: // (icmp pred (and X, XorCST), CI)
+if (ConstantInt *XorCST = dyn_castConstantInt(LHSI-getOperand(1))) {
+  // If this is a comparison that tests the signbit (X  0) or (x  
-1),
+  // fold the xor.
+  if (I.getPredicate() == ICmpInst::ICMP_SLT  CI-isZero() ||
+  I.getPredicate() == ICmpInst::ICMP_SGT  CI-isAllOnesValue()) {
+Value *CompareVal = LHSI-getOperand(0);
+
+// If the sign bit of the XorCST is not set, there is no change to
+// the operation, just stop using the Xor.
+if (!XorCST-getValue().isNegative()) {
+  I.setOperand(0, CompareVal);
+  AddToWorkList(LHSI);
+  return I;
+}
+
+// Was the old condition true if the operand is positive?
+bool isTrueIfPositive = I.getPredicate() == ICmpInst::ICMP_SGT;
+
+// If so, the new one isn't.
+isTrueIfPositive ^= true;
+
+if (isTrueIfPositive)
+  return new ICmpInst(ICmpInst::ICMP_SGT, CompareVal, SubOne(CI));
+else
+  return new ICmpInst(ICmpInst::ICMP_SLT, CompareVal, AddOne(CI));
+  }
+}
+break;
+  case Instruction::And: // (icmp pred (and X, AndCST), CI)
 if (LHSI-hasOneUse()  isaConstantInt(LHSI-getOperand(1)) 
 LHSI-getOperand(0)-hasOneUse()) {
   ConstantInt *AndCST = castConstantInt(LHSI-getOperand(1));



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-04-02 Thread Chris Lattner


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.724 - 1.725
---
Log message:

Split a whole ton of code out of visitICmpInst into 
visitICmpInstWithInstAndIntCst.


---
Diffs of the changes:  (+524 -520)

 InstructionCombining.cpp | 1044 +++
 1 files changed, 524 insertions(+), 520 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.724 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.725
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.724   Mon Apr  2 
20:47:41 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Mon Apr  2 23:46:52 2007
@@ -183,6 +183,9 @@
 Instruction *visitFCmpInst(FCmpInst I);
 Instruction *visitICmpInst(ICmpInst I);
 Instruction *visitICmpInstWithCastAndCast(ICmpInst ICI);
+Instruction *visitICmpInstWithInstAndIntCst(ICmpInst ICI,
+Instruction *LHS,
+ConstantInt *RHS);
 
 Instruction *FoldGEPICmp(User *GEPLHS, Value *RHS,
  ICmpInst::Predicate Cond, Instruction I);
@@ -4713,525 +4716,11 @@
 // instruction, see if that instruction also has constants so that the 
 // instruction can be folded into the icmp 
 if (Instruction *LHSI = dyn_castInstruction(Op0))
-  switch (LHSI-getOpcode()) {
-  case Instruction::Xor: // (icmp pred (and X, XorCST), CI)
-if (ConstantInt *XorCST = dyn_castConstantInt(LHSI-getOperand(1))) {
-  // If this is a comparison that tests the signbit (X  0) or (x  
-1),
-  // fold the xor.
-  if (I.getPredicate() == ICmpInst::ICMP_SLT  CI-isZero() ||
-  I.getPredicate() == ICmpInst::ICMP_SGT  CI-isAllOnesValue()) {
-Value *CompareVal = LHSI-getOperand(0);
-
-// If the sign bit of the XorCST is not set, there is no change to
-// the operation, just stop using the Xor.
-if (!XorCST-getValue().isNegative()) {
-  I.setOperand(0, CompareVal);
-  AddToWorkList(LHSI);
-  return I;
-}
-
-// Was the old condition true if the operand is positive?
-bool isTrueIfPositive = I.getPredicate() == ICmpInst::ICMP_SGT;
-
-// If so, the new one isn't.
-isTrueIfPositive ^= true;
-
-if (isTrueIfPositive)
-  return new ICmpInst(ICmpInst::ICMP_SGT, CompareVal, SubOne(CI));
-else
-  return new ICmpInst(ICmpInst::ICMP_SLT, CompareVal, AddOne(CI));
-  }
-}
-break;
-  case Instruction::And: // (icmp pred (and X, AndCST), CI)
-if (LHSI-hasOneUse()  isaConstantInt(LHSI-getOperand(1)) 
-LHSI-getOperand(0)-hasOneUse()) {
-  ConstantInt *AndCST = castConstantInt(LHSI-getOperand(1));
-
-  // If the LHS is an AND of a truncating cast, we can widen the
-  // and/compare to be the input width without changing the value
-  // produced, eliminating a cast.
-  if (CastInst *Cast = dyn_castCastInst(LHSI-getOperand(0))) {
-// We can do this transformation if either the AND constant does 
not
-// have its sign bit set or if it is an equality comparison. 
-// Extending a relational comparison when we're checking the sign
-// bit would not work.
-if (Cast-hasOneUse()  isaTruncInst(Cast) 
-(I.isEquality() || AndCST-getValue().isPositive()  
- CI-getValue().isPositive())) {
-  ConstantInt *NewCST;
-  ConstantInt *NewCI;
-  APInt NewCSTVal(AndCST-getValue()), NewCIVal(CI-getValue());
-  uint32_t BitWidth = castIntegerType(
-Cast-getOperand(0)-getType())-getBitWidth();
-  NewCST = ConstantInt::get(NewCSTVal.zext(BitWidth));
-  NewCI = ConstantInt::get(NewCIVal.zext(BitWidth));
-  Instruction *NewAnd = 
-BinaryOperator::createAnd(Cast-getOperand(0), NewCST, 
-  LHSI-getName());
-  InsertNewInstBefore(NewAnd, I);
-  return new ICmpInst(I.getPredicate(), NewAnd, NewCI);
-}
-  }
-  
-  // If this is: (X  C1)  C2 != C3 (where any shift and any compare
-  // could exist), turn it into (X  (C2  C1)) != (C3  C1).  This
-  // happens a LOT in code produced by the C front-end, for bitfield
-  // access.
-  BinaryOperator *Shift = 
dyn_castBinaryOperator(LHSI-getOperand(0));
-  if (Shift  !Shift-isShift())
-Shift = 0;
-
-  ConstantInt *ShAmt;
-  ShAmt = Shift ? dyn_castConstantInt(Shift-getOperand(1)) : 0;
-  const Type 

[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-04-01 Thread Reid Spencer


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.715 - 1.716
---
Log message:

For PR1297: http://llvm.org/PR1297 :
Support overloaded intrinsics bswap, ctpop, cttz, ctlz.


---
Diffs of the changes:  (+7 -25)

 InstructionCombining.cpp |   32 +++-
 1 files changed, 7 insertions(+), 25 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.715 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.716
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.715   Sun Apr  1 
00:36:37 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Sun Apr  1 02:35:23 2007
@@ -3624,11 +3624,11 @@
   Module *M = I.getParent()-getParent()-getParent();
   const char *FnName = 0;
   if (I.getType() == Type::Int16Ty)
-FnName = llvm.bswap.i16;
+FnName = llvm.bswap.i16.i16;
   else if (I.getType() == Type::Int32Ty)
-FnName = llvm.bswap.i32;
+FnName = llvm.bswap.i32.i32;
   else if (I.getType() == Type::Int64Ty)
-FnName = llvm.bswap.i64;
+FnName = llvm.bswap.i64.i64;
   else
 assert(0  Unknown integer type!);
   Constant *F = M-getOrInsertFunction(FnName, I.getType(), I.getType(), NULL);
@@ -5173,29 +5173,11 @@
 default: break;
 }
   } else if (IntrinsicInst *II = dyn_castIntrinsicInst(Op0)) {
-// Handle set{eq|ne} intrinsic, intcst.
-switch (II-getIntrinsicID()) {
-default: break;
-case Intrinsic::bswap_i16: 
-  // icmp eq (bswap(x)), c - icmp eq (x,bswap(c))
-  AddToWorkList(II);  // Dead?
-  I.setOperand(0, II-getOperand(1));
-  I.setOperand(1, ConstantInt::get(Type::Int16Ty,
-   ByteSwap_16(CI-getZExtValue(;
-  return I;
-case Intrinsic::bswap_i32:   
-  // icmp eq (bswap(x)), c - icmp eq (x,bswap(c))
-  AddToWorkList(II);  // Dead?
-  I.setOperand(0, II-getOperand(1));
-  I.setOperand(1, ConstantInt::get(Type::Int32Ty,
-   ByteSwap_32(CI-getZExtValue(;
-  return I;
-case Intrinsic::bswap_i64:   
-  // icmp eq (bswap(x)), c - icmp eq (x,bswap(c))
-  AddToWorkList(II);  // Dead?
+// Handle icmp {eq|ne} intrinsic, intcst.
+if (II-getIntrinsicID() == Intrinsic::bswap) {
+  AddToWorkList(II);
   I.setOperand(0, II-getOperand(1));
-  I.setOperand(1, ConstantInt::get(Type::Int64Ty,
-   ByteSwap_64(CI-getZExtValue(;
+  I.setOperand(1, ConstantInt::get(CI-getValue().byteSwap()));
   return I;
 }
   }



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-04-01 Thread Zhou Sheng


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.716 - 1.717
---
Log message:

Avoid unnecessary APInt construction.


---
Diffs of the changes:  (+17 -18)

 InstructionCombining.cpp |   35 +--
 1 files changed, 17 insertions(+), 18 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.716 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.717
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.716   Sun Apr  1 
02:35:23 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Sun Apr  1 12:13:37 2007
@@ -1870,7 +1870,7 @@
 
 if (ConstantInt *CI = dyn_castConstantInt(RHSC)) {
   // X + (signbit) -- X ^ signbit
-  APInt Val(CI-getValue());
+  const APInt Val = CI-getValue();
   unsigned BitWidth = Val.getBitWidth();
   if (Val == APInt::getSignBit(BitWidth))
 return BinaryOperator::createXor(LHS, RHS);
@@ -1894,7 +1894,7 @@
 if (isaConstantInt(RHSC) 
 match(LHS, m_Xor(m_Value(XorLHS), m_ConstantInt(XorRHS {
   unsigned TySizeBits = I.getType()-getPrimitiveSizeInBits();
-  APInt RHSVal(castConstantInt(RHSC)-getValue());
+  const APInt RHSVal = castConstantInt(RHSC)-getValue();
   
   unsigned Size = TySizeBits / 2;
   APInt C0080Val(APInt(TySizeBits, 1ULL).shl(Size - 1));
@@ -1999,14 +1999,13 @@
   if (Anded == CRHS) {
 // See if all bits from the first bit set in the Add RHS up are 
included
 // in the mask.  First, get the rightmost bit.
-APInt AddRHSV(CRHS-getValue());
+const APInt AddRHSV = CRHS-getValue();
 
 // Form a mask of all bits from the lowest bit added through the top.
-APInt AddRHSHighBits = ~((AddRHSV  -AddRHSV)-1);
-AddRHSHighBits = C2-getType()-getMask();
+APInt AddRHSHighBits(~((AddRHSV  -AddRHSV)-1));
 
 // See if the and mask includes all of these bits.
-APInt AddRHSHighBitsAnd = AddRHSHighBits  C2-getValue();
+APInt AddRHSHighBitsAnd(AddRHSHighBits  C2-getValue());
 
 if (AddRHSHighBits == AddRHSHighBitsAnd) {
   // Okay, the xform is safe.  Insert the new add pronto.
@@ -2451,7 +2450,7 @@
   if (BinaryOperator *RHSI = dyn_castBinaryOperator(I.getOperand(1))) {
 if (RHSI-getOpcode() == Instruction::Shl 
 isaConstantInt(RHSI-getOperand(0))) {
-  APInt C1(castConstantInt(RHSI-getOperand(0))-getValue());
+  const APInt C1 = castConstantInt(RHSI-getOperand(0))-getValue();
   if (C1.isPowerOf2()) {
 Value *N = RHSI-getOperand(1);
 const Type *NTy = N-getType();
@@ -2469,7 +2468,7 @@
   if (SelectInst *SI = dyn_castSelectInst(Op1)) 
 if (ConstantInt *STO = dyn_castConstantInt(SI-getOperand(1)))
   if (ConstantInt *SFO = dyn_castConstantInt(SI-getOperand(2)))  {
-APInt TVA(STO-getValue()), FVA(SFO-getValue());
+const APInt TVA = STO-getValue(), FVA = SFO-getValue();
 if (TVA.isPowerOf2()  FVA.isPowerOf2()) {
   // Compute the shift amounts
   uint32_t TSA = TVA.logBase2(), FSA = FVA.logBase2();
@@ -2934,14 +2933,14 @@
   // Adding a one to a single bit bit-field should be turned into an XOR
   // of the bit.  First thing to check is to see if this AND is with a
   // single bit constant.
-  APInt AndRHSV(castConstantInt(AndRHS)-getValue());
+  const APInt AndRHSV = castConstantInt(AndRHS)-getValue();
 
   // If there is only one bit set...
   if (isOneBitSet(castConstantInt(AndRHS))) {
 // Ok, at this point, we know that we are masking the result of the
 // ADD down to exactly one bit.  If the constant we are adding has
 // no bits set below this bit, then we can eliminate the ADD.
-APInt AddRHS(castConstantInt(OpRHS)-getValue());
+const APInt AddRHS = castConstantInt(OpRHS)-getValue();
 
 // Check to see if any bits below the one bit set in AndRHSV are set.
 if ((AddRHS  (AndRHSV-1)) == 0) {
@@ -3083,7 +3082,7 @@
 // MSB, so 0x000FFF0, 0x, and 0xFFFF are all runs.  0x0F0F is
 // not, since all 1s are not contiguous.
 static bool isRunOfOnes(ConstantInt *Val, unsigned MB, unsigned ME) {
-  APInt V = Val-getValue();
+  const APInt V = Val-getValue();
   uint32_t BitWidth = Val-getType()-getBitWidth();
   if (!APIntOps::isShiftedMask(BitWidth, V)) return false;
 
@@ -3180,9 +3179,8 @@
   }
   
   if (ConstantInt *AndRHS = dyn_castConstantInt(Op1)) {
-APInt AndRHSMask(AndRHS-getValue());
-APInt TypeMask(castIntegerType(Op0-getType())-getMask());
-APInt NotAndRHS = AndRHSMask^TypeMask;
+const APInt AndRHSMask = AndRHS-getValue();
+APInt NotAndRHS(~AndRHSMask);
 
 // Optimize a variety of ((val OP C1)  C2) combinations...
 if (isaBinaryOperator(Op0)) {
@@ -4675,7 +4673,8 @@
 if ((KnownOne | KnownZero) != 0) {
   // Compute the Min, Max 

[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-04-01 Thread Chris Lattner


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.717 - 1.718
---
Log message:

simplify this code, make it work for ap ints


---
Diffs of the changes:  (+6 -17)

 InstructionCombining.cpp |   23 ++-
 1 files changed, 6 insertions(+), 17 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.717 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.718
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.717   Sun Apr  1 
12:13:37 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Sun Apr  1 15:57:36 2007
@@ -3594,14 +3594,14 @@
 /// MatchBSwap - Given an OR instruction, check to see if this is a bswap 
idiom.
 /// If so, insert the new bswap intrinsic and return it.
 Instruction *InstCombiner::MatchBSwap(BinaryOperator I) {
-  // We cannot bswap one byte.
-  if (I.getType() == Type::Int8Ty)
-return 0;
+  const IntegerType *ITy = dyn_castIntegerType(I.getType());
+  if (!ITy || ITy-getBitWidth() % 16) 
+return 0;   // Can only bswap pairs of bytes.  Can't do vectors.
   
   /// ByteValues - For each byte of the result, we keep track of which value
   /// defines each byte.
   SmallVectorValue*, 8 ByteValues;
-  ByteValues.resize(TD-getTypeSize(I.getType()));
+  ByteValues.resize(ITy-getBitWidth()/8);
 
   // Try to find all the pieces corresponding to the bswap.
   if (CollectBSwapParts(I.getOperand(0), ByteValues) ||
@@ -3616,20 +3616,9 @@
   for (unsigned i = 1, e = ByteValues.size(); i != e; ++i)
 if (ByteValues[i] != V)
   return 0;
-
-  // If they do then *success* we can turn this into a bswap.  Figure out what
-  // bswap to make it into.
+  const Type *Tys[] = { ITy, ITy };
   Module *M = I.getParent()-getParent()-getParent();
-  const char *FnName = 0;
-  if (I.getType() == Type::Int16Ty)
-FnName = llvm.bswap.i16.i16;
-  else if (I.getType() == Type::Int32Ty)
-FnName = llvm.bswap.i32.i32;
-  else if (I.getType() == Type::Int64Ty)
-FnName = llvm.bswap.i64.i64;
-  else
-assert(0  Unknown integer type!);
-  Constant *F = M-getOrInsertFunction(FnName, I.getType(), I.getType(), NULL);
+  Function *F = Intrinsic::getDeclaration(M, Intrinsic::bswap, Tys, 2);
   return new CallInst(F, V);
 }
 



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-04-01 Thread Chris Lattner


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.718 - 1.719
---
Log message:

simplify (x+c)^signbit as (x+c+signbit), pointed out by PR1288: 
http://llvm.org/PR1288 .  This implements
test/Transforms/InstCombine/xor.ll:test28


---
Diffs of the changes:  (+7 -1)

 InstructionCombining.cpp |8 +++-
 1 files changed, 7 insertions(+), 1 deletion(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.718 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.719
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.718   Sun Apr  1 
15:57:36 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Mon Apr  2 00:36:22 2007
@@ -4005,7 +4005,7 @@
   return BinaryOperator::createOr(Op0NotVal, NotY);
 }
   }
-
+  
   if (ConstantInt *Op0CI = dyn_castConstantInt(Op0I-getOperand(1)))
 if (Op0I-getOpcode() == Instruction::Add) {
   // ~(X-c) -- (-c-1)-X
@@ -4015,6 +4015,12 @@
ConstantExpr::getSub(NegOp0CI,
  ConstantInt::get(I.getType(), 1)),
   Op0I-getOperand(0));
+  } else if (RHS-getValue().isMinSignedValue()) {
+// (X + C) ^ signbit - (X + C + signbit)
+Constant *C = ConstantInt::get(RHS-getValue() + 
Op0CI-getValue());
+return BinaryOperator::createAdd(Op0I-getOperand(0), C);
+ 
+  
   }
 } else if (Op0I-getOpcode() == Instruction::Or) {
   // (X|C1)^C2 - X^(C1|C2) iff X~C1 == 0



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-04-01 Thread Chris Lattner


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.719 - 1.720
---
Log message:

use more obvious function name.


---
Diffs of the changes:  (+1 -1)

 InstructionCombining.cpp |2 +-
 1 files changed, 1 insertion(+), 1 deletion(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.719 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.720
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.719   Mon Apr  2 
00:36:22 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Mon Apr  2 00:42:22 2007
@@ -4015,7 +4015,7 @@
ConstantExpr::getSub(NegOp0CI,
  ConstantInt::get(I.getType(), 1)),
   Op0I-getOperand(0));
-  } else if (RHS-getValue().isMinSignedValue()) {
+  } else if (RHS-getValue().isSignBit()) {
 // (X + C) ^ signbit - (X + C + signbit)
 Constant *C = ConstantInt::get(RHS-getValue() + 
Op0CI-getValue());
 return BinaryOperator::createAdd(Op0I-getOperand(0), C);



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-04-01 Thread Chris Lattner


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.720 - 1.721
---
Log message:

Wrap long line


---
Diffs of the changes:  (+3 -3)

 InstructionCombining.cpp |6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.720 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.721
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.720   Mon Apr  2 
00:42:22 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Mon Apr  2 00:48:58 2007
@@ -4019,8 +4019,7 @@
 // (X + C) ^ signbit - (X + C + signbit)
 Constant *C = ConstantInt::get(RHS-getValue() + 
Op0CI-getValue());
 return BinaryOperator::createAdd(Op0I-getOperand(0), C);
- 
-  
+
   }
 } else if (Op0I-getOpcode() == Instruction::Or) {
   // (X|C1)^C2 - X^(C1|C2) iff X~C1 == 0
@@ -6272,7 +6271,8 @@
   case Instruction::ZExt: {
 // We need to emit an AND to clear the high bits.
 assert(SrcBitSize  DestBitSize  Not a zext?);
-Constant *C = ConstantInt::get(APInt::getLowBitsSet(DestBitSize, 
SrcBitSize));
+Constant *C = ConstantInt::get(APInt::getLowBitsSet(DestBitSize,
+SrcBitSize));
 return BinaryOperator::createAnd(Res, C);
   }
   case Instruction::SExt:



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-03-31 Thread Chris Lattner


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.714 - 1.715
---
Log message:

Fix InstCombine/2007-03-31-InfiniteLoop.ll


---
Diffs of the changes:  (+3 -1)

 InstructionCombining.cpp |4 +++-
 1 files changed, 3 insertions(+), 1 deletion(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.714 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.715
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.714   Fri Mar 30 
21:50:26 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Sun Apr  1 00:36:37 2007
@@ -4083,8 +4083,10 @@
   else if (Op0 == B) // A^(B^A) == B
 return ReplaceInstUsesWith(I, A);
 } else if (match(Op1I, m_And(m_Value(A), m_Value(B)))  
Op1I-hasOneUse()){
-  if (A == Op0)// A^(AB) - 
A^(BA)
+  if (A == Op0) {  // A^(AB) - 
A^(BA)
 Op1I-swapOperands();
+std::swap(A, B);
+  }
   if (B == Op0) {  // A^(BA) - 
(BA)^A
 I.swapOperands(); // Simplified below.
 std::swap(Op0, Op1);



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-03-30 Thread Zhou Sheng


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.710 - 1.711
---
Log message:

1. Make sure the use of ConstantInt::getZExtValue() for getting shift
   amount is safe.
2. Use new method on ConstantInt instead of (? :) operator.
3. Use new method uge() on ConstantInt to simplify codes.


---
Diffs of the changes:  (+25 -27)

 InstructionCombining.cpp |   52 ++-
 1 files changed, 25 insertions(+), 27 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.710 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.711
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.710   Fri Mar 30 
00:45:18 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Fri Mar 30 04:29:48 2007
@@ -541,8 +541,7 @@
 if ((CST = dyn_castConstantInt(I-getOperand(1 {
   // The multiplier is really 1  CST.
   uint32_t BitWidth = castIntegerType(V-getType())-getBitWidth();
-  uint32_t CSTVal = CST-getValue().getActiveBits()  64 ?
-  BitWidth : CST-getZExtValue();
+  uint32_t CSTVal = CST-getLimitedValue(BitWidth);
   CST = ConstantInt::get(APInt(BitWidth, 1).shl(CSTVal));
   return I-getOperand(0);
 }
@@ -745,7 +744,7 @@
   case Instruction::Shl:
 // (shl X, C1)  C2 == 0   iff   (X  C2 u C1) == 0
 if (ConstantInt *SA = dyn_castConstantInt(I-getOperand(1))) {
-  uint64_t ShiftAmt = SA-getZExtValue();
+  uint64_t ShiftAmt = SA-getLimitedValue(BitWidth);
   APInt Mask2(Mask.lshr(ShiftAmt));
   ComputeMaskedBits(I-getOperand(0), Mask2, KnownZero, KnownOne, Depth+1);
   assert((KnownZero  KnownOne) == 0  Bits known to be one AND zero?); 
@@ -759,7 +758,7 @@
 // (ushr X, C1)  C2 == 0   iff  (-1  C1)  C2 == 0
 if (ConstantInt *SA = dyn_castConstantInt(I-getOperand(1))) {
   // Compute the new bits that are at the top now.
-  uint64_t ShiftAmt = SA-getZExtValue();
+  uint64_t ShiftAmt = SA-getLimitedValue(BitWidth);
   
   // Unsigned shift right.
   APInt Mask2(Mask.shl(ShiftAmt));
@@ -776,7 +775,7 @@
 // (ashr X, C1)  C2 == 0   iff  (-1  C1)  C2 == 0
 if (ConstantInt *SA = dyn_castConstantInt(I-getOperand(1))) {
   // Compute the new bits that are at the top now.
-  uint64_t ShiftAmt = SA-getZExtValue();
+  uint64_t ShiftAmt = SA-getLimitedValue(BitWidth);
   
   // Signed shift right.
   APInt Mask2(Mask.shl(ShiftAmt));
@@ -1306,7 +1305,7 @@
 break;
   case Instruction::Shl:
 if (ConstantInt *SA = dyn_castConstantInt(I-getOperand(1))) {
-  uint64_t ShiftAmt = SA-getZExtValue();
+  uint64_t ShiftAmt = SA-getLimitedValue(BitWidth);
   APInt DemandedMaskIn(DemandedMask.lshr(ShiftAmt));
   if (SimplifyDemandedBits(I-getOperand(0), DemandedMaskIn, 
RHSKnownZero, RHSKnownOne, Depth+1))
@@ -1323,7 +1322,7 @@
   case Instruction::LShr:
 // For a logical shift right
 if (ConstantInt *SA = dyn_castConstantInt(I-getOperand(1))) {
-  unsigned ShiftAmt = SA-getZExtValue();
+  uint64_t ShiftAmt = SA-getLimitedValue(BitWidth);
   
   // Unsigned shift right.
   APInt DemandedMaskIn(DemandedMask.shl(ShiftAmt));
@@ -2984,8 +2983,7 @@
 // the anded constant includes them, clear them now!
 //
 uint32_t BitWidth = AndRHS-getType()-getBitWidth();
-uint32_t OpRHSVal = OpRHS-getValue().getActiveBits()  64 ?
-BitWidth : OpRHS-getZExtValue();
+uint32_t OpRHSVal = OpRHS-getLimitedValue(BitWidth);
 APInt ShlMask(APInt::getHighBitsSet(BitWidth, BitWidth-OpRHSVal));
 ConstantInt *CI = ConstantInt::get(AndRHS-getValue()  ShlMask);
 
@@ -3005,8 +3003,7 @@
 // unsigned shifts, because a signed shr may bring in set bits!
 //
 uint32_t BitWidth = AndRHS-getType()-getBitWidth();
-uint32_t OpRHSVal = OpRHS-getValue().getActiveBits()  64 ?
-BitWidth : OpRHS-getZExtValue();
+uint32_t OpRHSVal = OpRHS-getLimitedValue(BitWidth);
 APInt ShrMask(APInt::getLowBitsSet(BitWidth, BitWidth - OpRHSVal));
 ConstantInt *CI = ConstantInt::get(AndRHS-getValue()  ShrMask);
 
@@ -3025,8 +3022,7 @@
 // with an and.
 if (Op-hasOneUse()) {
   uint32_t BitWidth = AndRHS-getType()-getBitWidth();
-  uint32_t OpRHSVal = OpRHS-getValue().getActiveBits()  64 ?
-  BitWidth : OpRHS-getZExtValue();
+  uint32_t OpRHSVal = OpRHS-getLimitedValue(BitWidth);
   APInt ShrMask(APInt::getLowBitsSet(BitWidth, BitWidth - OpRHSVal));
   Constant *C = ConstantInt::get(AndRHS-getValue()  ShrMask);
   if (C == AndRHS) {  // Masking out bits shifted in.
@@ -3541,11 +3537,12 @@
 return CollectBSwapParts(I-getOperand(0), ByteValues) ||
CollectBSwapParts(I-getOperand(1), ByteValues);
   
+  uint32_t 

[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-03-30 Thread Zhou Sheng


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.711 - 1.712
---
Log message:

Make sure the use of ConstantInt::getZExtValue() for shift amount safe.


---
Diffs of the changes:  (+20 -18)

 InstructionCombining.cpp |   38 --
 1 files changed, 20 insertions(+), 18 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.711 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.712
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.711   Fri Mar 30 
04:29:48 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Fri Mar 30 12:20:39 2007
@@ -1354,7 +1354,7 @@
 }
 
 if (ConstantInt *SA = dyn_castConstantInt(I-getOperand(1))) {
-  unsigned ShiftAmt = SA-getZExtValue();
+  uint32_t ShiftAmt = SA-getLimitedValue(BitWidth);
   
   // Signed shift right.
   APInt DemandedMaskIn(DemandedMask.shl(ShiftAmt));
@@ -2095,12 +2095,12 @@
 
 // -(X u 31) - (X s 31)
 // -(X s 31) - (X u 31)
-if (C-isNullValue()) {
+if (C-isZero()) {
   if (BinaryOperator *SI = dyn_castBinaryOperator(Op1))
 if (SI-getOpcode() == Instruction::LShr) {
   if (ConstantInt *CU = dyn_castConstantInt(SI-getOperand(1))) {
 // Check to see if we are shifting out everything but the sign bit.
-if (CU-getZExtValue() == 
+if (CU-getLimitedValue(SI-getType()-getPrimitiveSizeInBits()) ==
 SI-getType()-getPrimitiveSizeInBits()-1) {
   // Ok, the transformation is safe.  Insert AShr.
   return BinaryOperator::create(Instruction::AShr, 
@@ -2111,7 +2111,7 @@
 else if (SI-getOpcode() == Instruction::AShr) {
   if (ConstantInt *CU = dyn_castConstantInt(SI-getOperand(1))) {
 // Check to see if we are shifting out everything but the sign bit.
-if (CU-getZExtValue() == 
+if (CU-getLimitedValue(SI-getType()-getPrimitiveSizeInBits()) ==
 SI-getType()-getPrimitiveSizeInBits()-1) {
   // Ok, the transformation is safe.  Insert LShr. 
   return BinaryOperator::createLShr(
@@ -4789,7 +4789,8 @@
 if (!CanFold) {
   // To test for the bad case of the signed shr, see if any
   // of the bits shifted in could be tested after the mask.
-  int ShAmtVal = 
Ty-getPrimitiveSizeInBits()-ShAmt-getZExtValue();
+  uint32_t TyBits = Ty-getPrimitiveSizeInBits();
+  int ShAmtVal = TyBits - ShAmt-getLimitedValue(TyBits);
   if (ShAmtVal  0) ShAmtVal = 0; // Out of range shift.
 
   uint32_t BitWidth = AndTy-getPrimitiveSizeInBits();
@@ -4883,7 +4884,7 @@
 
 if (LHSI-hasOneUse()) {
   // Otherwise strength reduce the shift into an and.
-  unsigned ShAmtVal = (unsigned)ShAmt-getZExtValue();
+  uint32_t ShAmtVal = (uint32_t)ShAmt-getLimitedValue(TypeBits);
   uint64_t Val = (1ULL  (TypeBits-ShAmtVal))-1;
   Constant *Mask = ConstantInt::get(CI-getType(), Val);
 
@@ -4926,7 +4927,7 @@
 }
 
 if (LHSI-hasOneUse() || CI-isNullValue()) {
-  unsigned ShAmtVal = (unsigned)ShAmt-getZExtValue();
+  uint32_t ShAmtVal = (uint32_t)ShAmt-getLimitedValue(TypeBits);
 
   // Otherwise strength reduce the shift into an and.
   APInt Val(APInt::getHighBitsSet(TypeBits, TypeBits - ShAmtVal));
@@ -5658,7 +5659,7 @@
   BinaryOperator::create(Op0BO-getOpcode(), YS, V1,
  Op0BO-getOperand(1)-getName());
 InsertNewInstBefore(X, I);  // (X + (Y  C))
-uint32_t Op1Val = Op1-getZExtValue();
+uint32_t Op1Val = Op1-getLimitedValue(TypeBits);
 return BinaryOperator::createAnd(X, ConstantInt::get(
APInt::getHighBitsSet(TypeBits, TypeBits-Op1Val)));
   }
@@ -5697,7 +5698,7 @@
   BinaryOperator::create(Op0BO-getOpcode(), V1, YS,
  Op0BO-getOperand(0)-getName());
 InsertNewInstBefore(X, I);  // (X + (Y  C))
-uint32_t Op1Val = Op1-getZExtValue();
+uint32_t Op1Val = Op1-getLimitedValue(TypeBits);
 return BinaryOperator::createAnd(X, ConstantInt::get(
APInt::getHighBitsSet(TypeBits, TypeBits-Op1Val)));
   }
@@ -6084,8 +6085,9 @@
 // If we are truncating the result of this SHL, and if it's a shift of a
 // constant amount, we can always perform a SHL in a smaller type.
 if (ConstantInt *CI = dyn_castConstantInt(I-getOperand(1))) {
-  if (Ty-getBitWidth()  OrigTy-getBitWidth() 
-  CI-getZExtValue()  Ty-getBitWidth())
+  uint32_t BitWidth = Ty-getBitWidth();
+  if (BitWidth  OrigTy-getBitWidth()  
+  

[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-03-30 Thread Zhou Sheng


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.712 - 1.713
---
Log message:

Use APInt operators to calculate the carry bits, remove this loop.


---
Diffs of the changes:  (+2 -16)

 InstructionCombining.cpp |   18 ++
 1 files changed, 2 insertions(+), 16 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.712 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.713
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.712   Fri Mar 30 
12:20:39 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Fri Mar 30 21:38:39 2007
@@ -1243,22 +1243,8 @@
   // To compute this, we first compute the potential carry bits.  These are
   // the bits which may be modified.  I'm not aware of a better way to do
   // this scan.
-  APInt RHSVal(RHS-getValue());
-  
-  bool CarryIn = false;
-  APInt CarryBits(BitWidth, 0);
-  const uint64_t *LHSKnownZeroRawVal = LHSKnownZero.getRawData(),
- *RHSRawVal = RHSVal.getRawData();
-  for (uint32_t i = 0; i != RHSVal.getNumWords(); ++i) {
-uint64_t AddVal = ~LHSKnownZeroRawVal[i] + RHSRawVal[i],
- XorVal = ~LHSKnownZeroRawVal[i] ^ RHSRawVal[i];
-uint64_t WordCarryBits = AddVal ^ XorVal + CarryIn;
-if (AddVal  RHSRawVal[i])
-  CarryIn = true;
-else
-  CarryIn = false;
-CarryBits.setWordToValue(i, WordCarryBits);
-  }
+  const APInt RHSVal = RHS-getValue();
+  APInt CarryBits((~LHSKnownZero + RHSVal) ^ (~LHSKnownZero ^ RHSVal));
   
   // Now that we know which bits have carries, compute the known-1/0 sets.
   



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-03-30 Thread Zhou Sheng


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.713 - 1.714
---
Log message:

Delete dead code.


---
Diffs of the changes:  (+0 -1)

 InstructionCombining.cpp |1 -
 1 files changed, 1 deletion(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.713 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.714
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.713   Fri Mar 30 
21:38:39 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Fri Mar 30 21:50:26 2007
@@ -4777,7 +4777,6 @@
   // of the bits shifted in could be tested after the mask.
   uint32_t TyBits = Ty-getPrimitiveSizeInBits();
   int ShAmtVal = TyBits - ShAmt-getLimitedValue(TyBits);
-  if (ShAmtVal  0) ShAmtVal = 0; // Out of range shift.
 
   uint32_t BitWidth = AndTy-getPrimitiveSizeInBits();
   if ((APInt::getHighBitsSet(BitWidth, BitWidth-ShAmtVal)  



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


Re: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-03-30 Thread Chris Lattner
 Use APInt operators to calculate the carry bits, remove this loop.

Nice :)

-Chris



 ---
 Diffs of the changes:  (+2 -16)

  InstructionCombining.cpp |   18 ++
  1 files changed, 2 insertions(+), 16 deletions(-)


 Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
 diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.712  
 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.713
 --- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.712 Fri  
 Mar 30 12:20:39 2007
 +++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp   Fri Mar 30  
 21:38:39 2007
 @@ -1243,22 +1243,8 @@
// To compute this, we first compute the potential carry  
 bits.  These are
// the bits which may be modified.  I'm not aware of a  
 better way to do
// this scan.
 -  APInt RHSVal(RHS-getValue());
 -
 -  bool CarryIn = false;
 -  APInt CarryBits(BitWidth, 0);
 -  const uint64_t *LHSKnownZeroRawVal = LHSKnownZero.getRawData(),
 - *RHSRawVal = RHSVal.getRawData();
 -  for (uint32_t i = 0; i != RHSVal.getNumWords(); ++i) {
 -uint64_t AddVal = ~LHSKnownZeroRawVal[i] + RHSRawVal[i],
 - XorVal = ~LHSKnownZeroRawVal[i] ^ RHSRawVal[i];
 -uint64_t WordCarryBits = AddVal ^ XorVal + CarryIn;
 -if (AddVal  RHSRawVal[i])
 -  CarryIn = true;
 -else
 -  CarryIn = false;
 -CarryBits.setWordToValue(i, WordCarryBits);
 -  }
 +  const APInt RHSVal = RHS-getValue();
 +  APInt CarryBits((~LHSKnownZero + RHSVal) ^ (~LHSKnownZero ^  
 RHSVal));

// Now that we know which bits have carries, compute the  
 known-1/0 sets.




 ___
 llvm-commits mailing list
 llvm-commits@cs.uiuc.edu
 http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits

___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-03-29 Thread Zhou Sheng


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.708 - 1.709
---
Log message:

1. Make more use of APInt::getHighBitsSet/getLowBitsSet.
2. Let APInt variable do the binary operation stuff instead of using
   ConstantExpr::getXXX.


---
Diffs of the changes:  (+26 -22)

 InstructionCombining.cpp |   48 +--
 1 files changed, 26 insertions(+), 22 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.708 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.709
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.708   Wed Mar 28 
23:45:55 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Thu Mar 29 03:15:12 2007
@@ -1921,9 +1921,8 @@
   if ((RHSVal == CFF80Val  XorRHS-getValue() == C0080Val) ||
   (RHSVal == C0080Val  XorRHS-getValue() == CFF80Val)) {
 // This is a sign extend if the top bits are known zero.
-APInt Mask(APInt::getAllOnesValue(TySizeBits));
-Mask = Size;
-if (!MaskedValueIsZero(XorLHS, Mask))
+if (!MaskedValueIsZero(XorLHS, 
+   APInt::getHighBitsSet(TySizeBits, TySizeBits - Size)))
   Size = 0;  // Not a sign ext, but can't be any others either.
 break;
   }
@@ -2984,11 +2983,14 @@
 // We know that the AND will not produce any of the bits shifted in, so if
 // the anded constant includes them, clear them now!
 //
-Constant *AllOne = ConstantInt::getAllOnesValue(AndRHS-getType());
-Constant *ShlMask = ConstantExpr::getShl(AllOne, OpRHS);
-Constant *CI = ConstantExpr::getAnd(AndRHS, ShlMask);
+uint32_t BitWidth = AndRHS-getType()-getBitWidth();
+uint32_t OpRHSVal = OpRHS-getValue().getActiveBits()  64 ?
+BitWidth : OpRHS-getZExtValue();
+APInt ShlMask(APInt::getHighBitsSet(BitWidth, BitWidth-OpRHSVal));
+ConstantInt *CI = ConstantInt::get(AndRHS-getValue()  ShlMask);
 
-if (CI == ShlMask) {   // Masking out bits that the shift already masks
+if (CI-getValue() == ShlMask) { 
+// Masking out bits that the shift already masks
   return ReplaceInstUsesWith(TheAnd, Op);   // No need for the and.
 } else if (CI != AndRHS) {  // Reducing bits set in and.
   TheAnd.setOperand(1, CI);
@@ -3002,11 +3004,14 @@
 // the anded constant includes them, clear them now!  This only applies to
 // unsigned shifts, because a signed shr may bring in set bits!
 //
-Constant *AllOne = ConstantInt::getAllOnesValue(AndRHS-getType());
-Constant *ShrMask = ConstantExpr::getLShr(AllOne, OpRHS);
-Constant *CI = ConstantExpr::getAnd(AndRHS, ShrMask);
+uint32_t BitWidth = AndRHS-getType()-getBitWidth();
+uint32_t OpRHSVal = OpRHS-getValue().getActiveBits()  64 ?
+BitWidth : OpRHS-getZExtValue();
+APInt ShrMask(APInt::getLowBitsSet(BitWidth, BitWidth - OpRHSVal));
+ConstantInt *CI = ConstantInt::get(AndRHS-getValue()  ShrMask);
 
-if (CI == ShrMask) {   // Masking out bits that the shift already masks.
+if (CI-getValue() == ShrMask) {   
+// Masking out bits that the shift already masks.
   return ReplaceInstUsesWith(TheAnd, Op);
 } else if (CI != AndRHS) {
   TheAnd.setOperand(1, CI);  // Reduce bits set in and cst.
@@ -3019,9 +3024,11 @@
 // See if this is shifting in some sign extension, then masking it out
 // with an and.
 if (Op-hasOneUse()) {
-  Constant *AllOne = ConstantInt::getAllOnesValue(AndRHS-getType());
-  Constant *ShrMask = ConstantExpr::getLShr(AllOne, OpRHS);
-  Constant *C = ConstantExpr::getAnd(AndRHS, ShrMask);
+  uint32_t BitWidth = AndRHS-getType()-getBitWidth();
+  uint32_t OpRHSVal = OpRHS-getValue().getActiveBits()  64 ?
+  BitWidth : OpRHS-getZExtValue();
+  APInt ShrMask(APInt::getLowBitsSet(BitWidth, BitWidth - OpRHSVal));
+  Constant *C = ConstantInt::get(AndRHS-getValue()  ShrMask);
   if (C == AndRHS) {  // Masking out bits shifted in.
 // (Val ashr C1)  C2 - (Val lshr C1)  C2
 // Make the argument unsigned.
@@ -3140,8 +3147,7 @@
   unsigned MB = 0, ME = 0;
   if (isRunOfOnes(Mask, MB, ME)) {  // begin/end bit of run, inclusive
 uint32_t BitWidth = castIntegerType(RHS-getType())-getBitWidth();
-APInt Mask(APInt::getAllOnesValue(BitWidth));
-Mask = Mask.lshr(BitWidth-MB+1);
+APInt Mask(APInt::getLowBitsSet(BitWidth, MB-1));
 if (MaskedValueIsZero(RHS, Mask))
   break;
   }
@@ -4786,11 +4792,9 @@
   int ShAmtVal = 
Ty-getPrimitiveSizeInBits()-ShAmt-getZExtValue();
   if (ShAmtVal  0) ShAmtVal = 0; // Out of range shift.
 
-  Constant *OShAmt = ConstantInt::get(AndTy, ShAmtVal);
-  Constant *ShVal =
-

[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-03-29 Thread Zhou Sheng


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.709 - 1.710
---
Log message:

Use APInt operation instead of ConstantExpr::getXX.


---
Diffs of the changes:  (+6 -6)

 InstructionCombining.cpp |   12 ++--
 1 files changed, 6 insertions(+), 6 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.709 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.710
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.709   Thu Mar 29 
03:15:12 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Fri Mar 30 00:45:18 2007
@@ -5658,9 +5658,9 @@
   BinaryOperator::create(Op0BO-getOpcode(), YS, V1,
  Op0BO-getOperand(1)-getName());
 InsertNewInstBefore(X, I);  // (X + (Y  C))
-Constant *C2 = ConstantInt::getAllOnesValue(X-getType());
-C2 = ConstantExpr::getShl(C2, Op1);
-return BinaryOperator::createAnd(X, C2);
+uint32_t Op1Val = Op1-getZExtValue();
+return BinaryOperator::createAnd(X, ConstantInt::get(
+   APInt::getHighBitsSet(TypeBits, TypeBits-Op1Val)));
   }
   
   // Turn (Y + ((X  C)  CC))  C  -  ((X  (CC  C)) + (Y  C))
@@ -5697,9 +5697,9 @@
   BinaryOperator::create(Op0BO-getOpcode(), V1, YS,
  Op0BO-getOperand(0)-getName());
 InsertNewInstBefore(X, I);  // (X + (Y  C))
-Constant *C2 = ConstantInt::getAllOnesValue(X-getType());
-C2 = ConstantExpr::getShl(C2, Op1);
-return BinaryOperator::createAnd(X, C2);
+uint32_t Op1Val = Op1-getZExtValue();
+return BinaryOperator::createAnd(X, ConstantInt::get(
+   APInt::getHighBitsSet(TypeBits, TypeBits-Op1Val)));
   }
   
   // Turn (((X  C)CC) + Y)  C  -  (X + (Y  C))  (CC  C)



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


Re: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-03-29 Thread Chris Lattner

On Mar 28, 2007, at 6:57 PM, Zhou Sheng wrote:

 @@ -540,8 +540,10 @@
if (I-getOpcode() == Instruction::Shl)
  if ((CST = dyn_castConstantInt(I-getOperand(1 {
// The multiplier is really 1  CST.
 -  Constant *One = ConstantInt::get(V-getType(), 1);
 -  CST = castConstantInt(ConstantExpr::getShl(One, CST));
 +  uint32_t BitWidth = castIntegerType(V-getType())- 
 getBitWidth();
 +  uint32_t CSTVal = CST-getValue().getActiveBits()  64 ?
 +  BitWidth : CST-getZExtValue();
 +  CST = ConstantInt::get(APInt(BitWidth, 1).shl(CSTVal));
return I-getOperand(0);
  }
  }

I don't understand the logic here for the 64 active bits case.  Is  
the idea that the operation is undefined anyway?

-Chris
___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


Re: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-03-29 Thread Reid Spencer
On Thu, 2007-03-29 at 23:08 -0700, Chris Lattner wrote:
 On Mar 28, 2007, at 6:57 PM, Zhou Sheng wrote:
 
  @@ -540,8 +540,10 @@
 if (I-getOpcode() == Instruction::Shl)
   if ((CST = dyn_castConstantInt(I-getOperand(1 {
 // The multiplier is really 1  CST.
  -  Constant *One = ConstantInt::get(V-getType(), 1);
  -  CST = castConstantInt(ConstantExpr::getShl(One, CST));
  +  uint32_t BitWidth = castIntegerType(V-getType())- 
  getBitWidth();
  +  uint32_t CSTVal = CST-getValue().getActiveBits()  64 ?
  +  BitWidth : CST-getZExtValue();
  +  CST = ConstantInt::get(APInt(BitWidth, 1).shl(CSTVal));
 return I-getOperand(0);
   }
   }
 
 I don't understand the logic here for the 64 active bits case.  Is  
 the idea that the operation is undefined anyway?

Yes. The CST constant is the operand 1 of a shift, the shift amount. As
you noted in previous commits, we have to guard against using
getZExtValue even on shift amounts because they could be huge ( 64
bits). In such situations, we just set the shift amount to the bit width
(also undefined) and avoid the getZExtValue (and avoid the assert).

There will be several more of these. Actually I asked Sheng to change
these to use a new method on ConstantInt since the idiom appears to be
cropping up all over the place (every shift examination).

Reid.

 
 -Chris
 ___
 llvm-commits mailing list
 llvm-commits@cs.uiuc.edu
 http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits

___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


Re: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-03-29 Thread Chris Lattner

On Mar 28, 2007, at 7:26 PM, Zhou Sheng wrote:

 InstructionCombining.cpp updated: 1.706 - 1.707
 ---
 Log message:

 Clean up codes in InstCombiner::SimplifyDemandedBits():
 1. Line out nested call of APInt::zext/trunc.
 2. Make more use of APInt::getHighBitsSet/getLowBitsSet.
 3. Use APInt[] operator instead of expression like APIntVal   
 SignBit.

Very nice, thanks for these cleanups!

-Chris
___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


Re: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-03-29 Thread Zhou Sheng
在 2007-03-29四的 23:20 -0700,Reid Spencer写道:
 On Thu, 2007-03-29 at 23:08 -0700, Chris Lattner wrote:
  On Mar 28, 2007, at 6:57 PM, Zhou Sheng wrote:
  
   @@ -540,8 +540,10 @@
  if (I-getOpcode() == Instruction::Shl)
if ((CST = dyn_castConstantInt(I-getOperand(1 {
  // The multiplier is really 1  CST.
   -  Constant *One = ConstantInt::get(V-getType(), 1);
   -  CST = castConstantInt(ConstantExpr::getShl(One, CST));
   +  uint32_t BitWidth = castIntegerType(V-getType())- 
   getBitWidth();
   +  uint32_t CSTVal = CST-getValue().getActiveBits()  64 ?
   +  BitWidth : CST-getZExtValue();
   +  CST = ConstantInt::get(APInt(BitWidth, 1).shl(CSTVal));
  return I-getOperand(0);
}
}
  
  I don't understand the logic here for the 64 active bits case.  Is  
  the idea that the operation is undefined anyway?
 
 Yes. The CST constant is the operand 1 of a shift, the shift amount. As
 you noted in previous commits, we have to guard against using
 getZExtValue even on shift amounts because they could be huge ( 64
 bits). In such situations, we just set the shift amount to the bit width
 (also undefined) and avoid the getZExtValue (and avoid the assert).
 
 There will be several more of these. Actually I asked Sheng to change
 these to use a new method on ConstantInt since the idiom appears to be
 cropping up all over the place (every shift examination).
This patch was committed two days ago. I'll update it to use the new
ConstantInt method.


Sheng.


 
 Reid.
 
  
  -Chris
  ___
  llvm-commits mailing list
  llvm-commits@cs.uiuc.edu
  http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
 

___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-03-28 Thread Zhou Sheng


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.702 - 1.703
---
Log message:

1. Make more use of getLowBitsSet/getHighBitsSet.
2. Make the APInt value do the zext/trunc stuff instead of using 
   ConstantExpr::getZExt().


---
Diffs of the changes:  (+3 -5)

 InstructionCombining.cpp |8 +++-
 1 files changed, 3 insertions(+), 5 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.702 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.703
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.702   Wed Mar 28 
00:15:57 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Wed Mar 28 04:19:01 2007
@@ -6304,8 +6304,7 @@
   case Instruction::ZExt: {
 // We need to emit an AND to clear the high bits.
 assert(SrcBitSize  DestBitSize  Not a zext?);
-Constant *C = ConstantInt::get(APInt::getAllOnesValue(SrcBitSize));
-C = ConstantExpr::getZExt(C, DestTy);
+Constant *C = ConstantInt::get(APInt::getLowBitsSet(DestBitSize, 
SrcBitSize));
 return BinaryOperator::createAnd(Res, C);
   }
   case Instruction::SExt:
@@ -6487,8 +6486,7 @@
 unsigned ShAmt = ShAmtV-getZExtValue();
 
 // Get a mask for the bits shifting in.
-APInt Mask(APInt::getAllOnesValue(SrcBitWidth).lshr(
- SrcBitWidth-ShAmt).shl(DestBitWidth));
+APInt Mask(APInt::getLowBitsSet(SrcBitWidth, ShAmt).shl(DestBitWidth));
 Value* SrcIOp0 = SrcI-getOperand(0);
 if (SrcI-hasOneUse()  MaskedValueIsZero(SrcIOp0, Mask)) {
   if (ShAmt = DestBitWidth)// All zeros.
@@ -6547,7 +6545,7 @@
   // If we're actually extending zero bits and the trunc is a no-op
   if (MidSize  DstSize  SrcSize == DstSize) {
 // Replace both of the casts with an And of the type mask.
-APInt AndValue(APInt::getAllOnesValue(MidSize).zext(SrcSize));
+APInt AndValue(APInt::getLowBitsSet(SrcSize, MidSize));
 Constant *AndConst = ConstantInt::get(AndValue);
 Instruction *And = 
   BinaryOperator::createAnd(CSrc-getOperand(0), AndConst);



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


Re: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-03-28 Thread Reid Spencer
On Wed, 2007-03-28 at 14:23 +0800, Zhou Sheng wrote:
 在 2007-03-27二的 22:17 -0700,Reid Spencer写道:

   KnownOne |= NewBits;
-  KnownZero = ~NewBits;
-} else {  // Input sign bit unknown
-  KnownZero = ~NewBits;
-  KnownOne = ~NewBits;
-}
   
   Why did you delete this? What if the sign bit is unknown? (neither known
   one nor known zero).  Please revert.
  
  This however is still a problem. It is quite possible for KnownZero[X]
  and KnownOne[X] to both be false.
 I looked into the context, the *else* case is possible, but, as the
 NewBits are : 
 
 APInt NewBits(APInt::getHighBitsSet(BitWidth, BitWidth - SrcBitWidth));
 
 So ~NewBits should be a Mask of SrcBitWidth, and as KnownZero, KnownOne
 are just zexted from SrcBitWidth to BitWidth, so, the = operation will
 be useless.

I see. I didn't have the full context on the trunc/zext. However, now
what you can do is move the construction of NewBits into each of the two
cases. This will avoid constructing it in the event that the sign bit is
not sent in either KnownZero nor KnownOne.

Thanks Sheng,

Reid.


___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-03-28 Thread Zhou Sheng


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.703 - 1.704
---
Log message:

1. Make more use of getLowBitsSet/getHighBitsSet.
2. Use APInt[] instead of X  SignBit.
3. Clean up some codes.
4. Make the expression like ShiftAmt = ShiftAmtC-getZExtValue() safe.


---
Diffs of the changes:  (+16 -13)

 InstructionCombining.cpp |   29 -
 1 files changed, 16 insertions(+), 13 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.703 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.704
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.703   Wed Mar 28 
04:19:01 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Wed Mar 28 10:02:20 2007
@@ -1313,7 +1313,7 @@
   RHSKnownOne  = ShiftAmt;
   // low bits known zero.
   if (ShiftAmt)
-RHSKnownZero |= APInt::getAllOnesValue(ShiftAmt).zextOrCopy(BitWidth);
+RHSKnownZero |= APInt::getLowBitsSet(BitWidth, ShiftAmt);
 }
 break;
   case Instruction::LShr:
@@ -5608,7 +5608,7 @@
   // shl uint X, 32 = 0 and shr ubyte Y, 9 = 0, ... just don't eliminate shr
   // of a signed value.
   //
-  if (Op1-getZExtValue() = TypeBits) {  // shift amount always = 32 bits
+  if (Op1-getValue().getActiveBits()  64 || Op1-getZExtValue() = TypeBits) 
{
 if (I.getOpcode() != Instruction::AShr)
   return ReplaceInstUsesWith(I, Constant::getNullValue(Op0-getType()));
 else {
@@ -5751,8 +5751,7 @@
 // operation.
 //
 if (isValid  !isLeftShift  I.getOpcode() == Instruction::AShr) {
-  isValid = ((Op0C-getValue()  APInt::getSignBit(TypeBits)) != 0) == 
-highBitSet;
+  isValid = Op0C-getValue()[TypeBits-1] == highBitSet;
 }
 
 if (isValid) {
@@ -5777,9 +5776,10 @@
   
   if (ShiftOp  isaConstantInt(ShiftOp-getOperand(1))) {
 ConstantInt *ShiftAmt1C = castConstantInt(ShiftOp-getOperand(1));
-// These shift amounts are always = 32 bits.
-unsigned ShiftAmt1 = (unsigned)ShiftAmt1C-getZExtValue();
-unsigned ShiftAmt2 = (unsigned)Op1-getZExtValue();
+uint32_t ShiftAmt1 = ShiftAmt1C-getValue().getActiveBits()  64 ? 
+   TypeBits : (uint32_t)ShiftAmt1C-getZExtValue();
+uint32_t ShiftAmt2 = Op1-getValue().getActiveBits()  64 ? 
+   TypeBits : (uint32_t)Op1-getZExtValue();
 assert(ShiftAmt2 != 0  Should have been simplified earlier);
 if (ShiftAmt1 == 0) return 0;  // Will be simplified in the future.
 Value *X = ShiftOp-getOperand(0);
@@ -5805,7 +5805,7 @@
 BinaryOperator::createAShr(X, ConstantInt::get(Ty, AmtSum));
   InsertNewInstBefore(Shift, I);
 
-  APInt Mask(Ty-getMask().lshr(ShiftAmt2));
+  APInt Mask(APInt::getLowBitsSet(TypeBits, TypeBits - ShiftAmt2));
   return BinaryOperator::createAnd(Shift, ConstantInt::get(Mask));
 }
 
@@ -5828,11 +5828,14 @@
   // generators.
   const Type *SExtType = 0;
   switch (Ty-getBitWidth() - ShiftAmt1) {
-  case 1  : SExtType = Type::Int1Ty; break;
-  case 8  : SExtType = Type::Int8Ty; break;
-  case 16 : SExtType = Type::Int16Ty; break;
-  case 32 : SExtType = Type::Int32Ty; break;
-  case 64 : SExtType = Type::Int64Ty; break;
+  case 1  :
+  case 8  :
+  case 16 :
+  case 32 :
+  case 64 :
+  case 128:
+SExtType = IntegerType::get(Ty-getBitWidth() - ShiftAmt1);
+break;
   default: break;
   }
   if (SExtType) {



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-03-28 Thread Zhou Sheng


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.704 - 1.705
---
Log message:

Avoid unnecessary APInt construction.


---
Diffs of the changes:  (+2 -3)

 InstructionCombining.cpp |5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.704 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.705
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.704   Wed Mar 28 
10:02:20 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Wed Mar 28 12:38:21 2007
@@ -734,11 +734,10 @@
 
 // If the sign bit of the input is known set or clear, then we know the
 // top bits of the result.
-APInt NewBits(APInt::getHighBitsSet(BitWidth, BitWidth - SrcBitWidth));
 if (KnownZero[SrcBitWidth-1]) // Input sign bit known zero
-  KnownZero |= NewBits;
+  KnownZero |= APInt::getHighBitsSet(BitWidth, BitWidth - SrcBitWidth);
 else if (KnownOne[SrcBitWidth-1])   // Input sign bit known set
-  KnownOne |= NewBits;
+  KnownOne |= APInt::getHighBitsSet(BitWidth, BitWidth - SrcBitWidth);
 return;
   }
   case Instruction::Shl:



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-03-28 Thread Zhou Sheng


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.705 - 1.706
---
Log message:

1. Make the APInt variable do the binary operation stuff if possible
   instead of using ConstantExpr::getXX.
2. Use constant reference to APInt if possible instead of expensive
   APInt copy.


---
Diffs of the changes:  (+5 -3)

 InstructionCombining.cpp |8 +---
 1 files changed, 5 insertions(+), 3 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.705 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.706
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.705   Wed Mar 28 
12:38:21 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Wed Mar 28 20:57:21 2007
@@ -540,8 +540,10 @@
   if (I-getOpcode() == Instruction::Shl)
 if ((CST = dyn_castConstantInt(I-getOperand(1 {
   // The multiplier is really 1  CST.
-  Constant *One = ConstantInt::get(V-getType(), 1);
-  CST = castConstantInt(ConstantExpr::getShl(One, CST));
+  uint32_t BitWidth = castIntegerType(V-getType())-getBitWidth();
+  uint32_t CSTVal = CST-getValue().getActiveBits()  64 ?
+  BitWidth : CST-getZExtValue();
+  CST = ConstantInt::get(APInt(BitWidth, 1).shl(CSTVal));
   return I-getOperand(0);
 }
 }
@@ -2264,7 +2266,7 @@
   if (CI-isAllOnesValue())  // X * -1 == 0 - X
 return BinaryOperator::createNeg(Op0, I.getName());
 
-  APInt Val(castConstantInt(CI)-getValue());
+  const APInt Val = castConstantInt(CI)-getValue();
   if (Val.isPowerOf2()) {  // Replace X*(2^C) with X  C
 return BinaryOperator::createShl(Op0,
  ConstantInt::get(Op0-getType(), Val.logBase2()));



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-03-28 Thread Zhou Sheng


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.706 - 1.707
---
Log message:

Clean up codes in InstCombiner::SimplifyDemandedBits():
1. Line out nested call of APInt::zext/trunc.
2. Make more use of APInt::getHighBitsSet/getLowBitsSet.
3. Use APInt[] operator instead of expression like APIntVal  SignBit.


---
Diffs of the changes:  (+35 -32)

 InstructionCombining.cpp |   67 ---
 1 files changed, 35 insertions(+), 32 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.706 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.707
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.706   Wed Mar 28 
20:57:21 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Wed Mar 28 21:26:30 2007
@@ -1106,8 +1106,11 @@
   case Instruction::Trunc: {
 uint32_t truncBf = 
   castIntegerType(I-getOperand(0)-getType())-getBitWidth();
-if (SimplifyDemandedBits(I-getOperand(0), DemandedMask.zext(truncBf),
-RHSKnownZero.zext(truncBf), RHSKnownOne.zext(truncBf), Depth+1))
+DemandedMask.zext(truncBf);
+RHSKnownZero.zext(truncBf);
+RHSKnownOne.zext(truncBf);
+if (SimplifyDemandedBits(I-getOperand(0), DemandedMask, 
+ RHSKnownZero, RHSKnownOne, Depth+1))
   return true;
 DemandedMask.trunc(BitWidth);
 RHSKnownZero.trunc(BitWidth);
@@ -1130,12 +1133,14 @@
 // Compute the bits in the result that are not present in the input.
 const IntegerType *SrcTy = castIntegerType(I-getOperand(0)-getType());
 uint32_t SrcBitWidth = SrcTy-getBitWidth();
-APInt NewBits(APInt::getHighBitsSet(BitWidth, BitWidth - SrcBitWidth));
 
 DemandedMask = SrcTy-getMask().zext(BitWidth);
 uint32_t zextBf = SrcTy-getBitWidth();
-if (SimplifyDemandedBits(I-getOperand(0), DemandedMask.trunc(zextBf),
-  RHSKnownZero.trunc(zextBf), RHSKnownOne.trunc(zextBf), Depth+1))
+DemandedMask.trunc(zextBf);
+RHSKnownZero.trunc(zextBf);
+RHSKnownOne.trunc(zextBf);
+if (SimplifyDemandedBits(I-getOperand(0), DemandedMask,
+ RHSKnownZero, RHSKnownOne, Depth+1))
   return true;
 DemandedMask.zext(BitWidth);
 RHSKnownZero.zext(BitWidth);
@@ -1143,29 +1148,32 @@
 assert((RHSKnownZero  RHSKnownOne) == 0  
Bits known to be one AND zero?); 
 // The top bits are known to be zero.
-RHSKnownZero |= NewBits;
+RHSKnownZero |= APInt::getHighBitsSet(BitWidth, BitWidth - SrcBitWidth);
 break;
   }
   case Instruction::SExt: {
 // Compute the bits in the result that are not present in the input.
 const IntegerType *SrcTy = castIntegerType(I-getOperand(0)-getType());
 uint32_t SrcBitWidth = SrcTy-getBitWidth();
-APInt NewBits(APInt::getHighBitsSet(BitWidth, BitWidth - SrcBitWidth));
 
 // Get the sign bit for the source type
-APInt InSignBit(APInt::getSignBit(SrcTy-getPrimitiveSizeInBits()));
+APInt InSignBit(APInt::getSignBit(SrcBitWidth));
 InSignBit.zext(BitWidth);
 APInt InputDemandedBits = DemandedMask  
-  SrcTy-getMask().zext(BitWidth);
+  APInt::getLowBitsSet(BitWidth, SrcBitWidth);
 
+APInt NewBits(APInt::getHighBitsSet(BitWidth, BitWidth - SrcBitWidth));
 // If any of the sign extended bits are demanded, we know that the sign
 // bit is demanded.
 if ((NewBits  DemandedMask) != 0)
   InputDemandedBits |= InSignBit;
   
 uint32_t sextBf = SrcTy-getBitWidth();
-if (SimplifyDemandedBits(I-getOperand(0), InputDemandedBits.trunc(sextBf),
-  RHSKnownZero.trunc(sextBf), RHSKnownOne.trunc(sextBf), Depth+1))
+InputDemandedBits.trunc(sextBf);
+RHSKnownZero.trunc(sextBf);
+RHSKnownOne.trunc(sextBf);
+if (SimplifyDemandedBits(I-getOperand(0), InputDemandedBits,
+ RHSKnownZero, RHSKnownOne, Depth+1))
   return true;
 InputDemandedBits.zext(BitWidth);
 RHSKnownZero.zext(BitWidth);
@@ -1178,12 +1186,12 @@
 
 // If the input sign bit is known zero, or if the NewBits are not demanded
 // convert this into a zero extension.
-if ((RHSKnownZero  InSignBit) != 0 || (NewBits  ~DemandedMask) == 
NewBits)
+if (RHSKnownZero[SrcBitWidth-1] || (NewBits  ~DemandedMask) == NewBits)
 {
   // Convert to ZExt cast
   CastInst *NewCast = new ZExtInst(I-getOperand(0), VTy, I-getName(), I);
   return UpdateValueUsesWith(I, NewCast);
-} else if ((RHSKnownOne  InSignBit) != 0) {// Input sign bit known set
+} else if (RHSKnownOne[SrcBitWidth-1]) {// Input sign bit known set
   RHSKnownOne |= NewBits;
   RHSKnownZero = ~NewBits;
 } else {  // Input sign bit unknown
@@ -1208,7 +1216,7 @@
   
   // If the top bit of the output is demanded, demand everything from 

[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-03-27 Thread Evan Cheng


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.697 - 1.698
---
Log message:

Unbreaks non-debug builds.

---
Diffs of the changes:  (+2 -0)

 InstructionCombining.cpp |2 ++
 1 files changed, 2 insertions(+)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.697 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.698
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.697   Mon Mar 26 
18:58:26 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Tue Mar 27 11:44:48 2007
@@ -9488,8 +9488,10 @@
 // Erase the old instruction.
 InstParent-getInstList().erase(I);
   } else {
+#ifndef NDEBUG
 DOUT  IC: Mod =   OrigI
   New =   *I;
+#endif
 
 // If the instruction was modified, it's possible that it is now dead.
 // if so, remove it.



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-03-27 Thread Reid Spencer


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.698 - 1.699
---
Log message:

For PR1280: http://llvm.org/PR1280 :
When converting an add/xor/and triplet into a trunc/sext, only do so if the
intermediate integer type is a bitwidth that the targets can handle.


---
Diffs of the changes:  (+13 -3)

 InstructionCombining.cpp |   16 +---
 1 files changed, 13 insertions(+), 3 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.698 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.699
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.698   Tue Mar 27 
11:44:48 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Tue Mar 27 20:36:16 2007
@@ -1940,11 +1940,21 @@
 CFF80Val = APIntOps::ashr(CFF80Val, Size);
   } while (Size = 1);
   
-  if (Size) {
-const Type *MiddleType = IntegerType::get(Size);
+  // FIXME: This shouldn't be necessary. When the backends can handle types
+  // with funny bit widths then this whole cascade of if statements should
+  // be removed. It is just here to get the size of the middle type back
+  // up to something that the back ends can handle.
+  const Type *MiddleType = 0;
+  switch (Size) {
+default: break;
+case 32: MiddleType = Type::Int32Ty; break;
+case 16: MiddleType = Type::Int16Ty; break;
+case  8: MiddleType = Type::Int8Ty; break;
+  }
+  if (MiddleType) {
 Instruction *NewTrunc = new TruncInst(XorLHS, MiddleType, sext);
 InsertNewInstBefore(NewTrunc, I);
-return new SExtInst(NewTrunc, I.getType());
+return new SExtInst(NewTrunc, I.getType(), I.getName());
   }
 }
   }



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-03-27 Thread Zhou Sheng


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.699 - 1.700
---
Log message:

Clean up codes in ComputeMaskedBits():
1. Line out nested use of zext/trunc.
2. Make more use of getHighBitsSet/getLowBitsSet.
3. Use APInt[] != 0 instead of (APInt  SignBit) != 0.


---
Diffs of the changes:  (+27 -29)

 InstructionCombining.cpp |   56 ++-
 1 files changed, 27 insertions(+), 29 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.699 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.700
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.699   Tue Mar 27 
20:36:16 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Tue Mar 27 21:19:03 2007
@@ -600,11 +600,10 @@
   assert(V  No Value?);
   assert(Depth = 6  Limit Search Depth);
   uint32_t BitWidth = Mask.getBitWidth();
-  const IntegerType *VTy = castIntegerType(V-getType());
-  assert(VTy-getBitWidth() == BitWidth 
+  assert(castIntegerType(V-getType())-getBitWidth() == BitWidth 
  KnownZero.getBitWidth() == BitWidth  
  KnownOne.getBitWidth() == BitWidth 
- VTy, Mask, KnownOne and KnownZero should have same BitWidth);
+ V, Mask, KnownOne and KnownZero should have same BitWidth);
   if (ConstantInt *CI = dyn_castConstantInt(V)) {
 // We know all of the bits for a constant!
 KnownOne = CI-getValue()  Mask;
@@ -685,8 +684,11 @@
 // All these have integer operands
 uint32_t SrcBitWidth = 
   castIntegerType(I-getOperand(0)-getType())-getBitWidth();
-ComputeMaskedBits(I-getOperand(0), APInt(Mask).zext(SrcBitWidth), 
-  KnownZero.zext(SrcBitWidth), KnownOne.zext(SrcBitWidth), Depth+1);
+APInt MaskIn(Mask);
+MaskIn.zext(SrcBitWidth);
+KnownZero.zext(SrcBitWidth);
+KnownOne.zext(SrcBitWidth);
+ComputeMaskedBits(I-getOperand(0), MaskIn, KnownZero, KnownOne, Depth+1);
 KnownZero.trunc(BitWidth);
 KnownOne.trunc(BitWidth);
 return;
@@ -703,43 +705,40 @@
 // Compute the bits in the result that are not present in the input.
 const IntegerType *SrcTy = castIntegerType(I-getOperand(0)-getType());
 uint32_t SrcBitWidth = SrcTy-getBitWidth();
-APInt NewBits(APInt::getHighBitsSet(BitWidth, BitWidth - SrcBitWidth));
   
-ComputeMaskedBits(I-getOperand(0), APInt(Mask).trunc(SrcBitWidth), 
-  KnownZero.trunc(SrcBitWidth), KnownOne.trunc(SrcBitWidth), Depth+1);
+APInt MaskIn(Mask);
+MaskIn.trunc(SrcBitWidth);
+KnownZero.trunc(SrcBitWidth);
+KnownOne.trunc(SrcBitWidth);
+ComputeMaskedBits(I-getOperand(0), MaskIn, KnownZero, KnownOne, Depth+1);
 assert((KnownZero  KnownOne) == 0  Bits known to be one AND zero?); 
 // The top bits are known to be zero.
 KnownZero.zext(BitWidth);
 KnownOne.zext(BitWidth);
-KnownZero |= NewBits;
+KnownZero |= APInt::getHighBitsSet(BitWidth, BitWidth - SrcBitWidth);
 return;
   }
   case Instruction::SExt: {
 // Compute the bits in the result that are not present in the input.
 const IntegerType *SrcTy = castIntegerType(I-getOperand(0)-getType());
 uint32_t SrcBitWidth = SrcTy-getBitWidth();
-APInt NewBits(APInt::getHighBitsSet(BitWidth, BitWidth - SrcBitWidth));
   
-ComputeMaskedBits(I-getOperand(0), APInt(Mask).trunc(SrcBitWidth), 
-  KnownZero.trunc(SrcBitWidth), KnownOne.trunc(SrcBitWidth), Depth+1);
+APInt MaskIn(Mask); 
+MaskIn.trunc(SrcBitWidth);
+KnownZero.trunc(SrcBitWidth);
+KnownOne.trunc(SrcBitWidth);
+ComputeMaskedBits(I-getOperand(0), MaskIn, KnownZero, KnownOne, Depth+1);
 assert((KnownZero  KnownOne) == 0  Bits known to be one AND zero?); 
 KnownZero.zext(BitWidth);
 KnownOne.zext(BitWidth);
 
 // If the sign bit of the input is known set or clear, then we know the
 // top bits of the result.
-APInt InSignBit(APInt::getSignBit(SrcTy-getBitWidth()));
-InSignBit.zext(BitWidth);
-if ((KnownZero  InSignBit) != 0) {  // Input sign bit known zero
+APInt NewBits(APInt::getHighBitsSet(BitWidth, BitWidth - SrcBitWidth));
+if (KnownZero[SrcBitWidth-1]) // Input sign bit known zero
   KnownZero |= NewBits;
-  KnownOne = ~NewBits;
-} else if ((KnownOne  InSignBit) != 0) {// Input sign bit known set
+else if (KnownOne[SrcBitWidth-1])   // Input sign bit known set
   KnownOne |= NewBits;
-  KnownZero = ~NewBits;
-} else {  // Input sign bit unknown
-  KnownZero = ~NewBits;
-  KnownOne = ~NewBits;
-}
 return;
   }
   case Instruction::Shl:
@@ -760,7 +759,6 @@
 if (ConstantInt *SA = dyn_castConstantInt(I-getOperand(1))) {
   // Compute the new bits that are at the top now.
   uint64_t ShiftAmt = SA-getZExtValue();
-  APInt HighBits(APInt::getHighBitsSet(BitWidth, ShiftAmt));
   
   // 

[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-03-27 Thread Zhou Sheng


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.700 - 1.701
---
Log message:

Remove unused APInt variable.


---
Diffs of the changes:  (+0 -3)

 InstructionCombining.cpp |3 ---
 1 files changed, 3 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.700 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.701
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.700   Tue Mar 27 
21:19:03 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Tue Mar 27 22:02:21 2007
@@ -784,9 +784,6 @@
   KnownZero = APIntOps::lshr(KnownZero, ShiftAmt);
   KnownOne  = APIntOps::lshr(KnownOne, ShiftAmt);
 
-  // Handle the sign bits and adjust to where it is now in the mask.
-  APInt SignBit(APInt::getSignBit(BitWidth).lshr(ShiftAmt));
-
   APInt HighBits(APInt::getHighBitsSet(BitWidth, ShiftAmt));
   if (KnownZero[BitWidth-ShiftAmt-1])// New bits are known zero.
 KnownZero |= HighBits;



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


Re: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-03-27 Thread Reid Spencer
Sheng,

Some important feedback ..

Reid.

On Tue, 2007-03-27 at 21:19 -0500, Zhou Sheng wrote:
 
 Changes in directory llvm/lib/Transforms/Scalar:
 
 InstructionCombining.cpp updated: 1.699 - 1.700
 ---
 Log message:
 
 Clean up codes in ComputeMaskedBits():
 1. Line out nested use of zext/trunc.
 2. Make more use of getHighBitsSet/getLowBitsSet.
 3. Use APInt[] != 0 instead of (APInt  SignBit) != 0.
 
 
 ---
 Diffs of the changes:  (+27 -29)
 
  InstructionCombining.cpp |   56 
 ++-
  1 files changed, 27 insertions(+), 29 deletions(-)
 
 
 Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
 diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.699 
 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.700
 --- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.699 Tue Mar 27 
 20:36:16 2007
 +++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp   Tue Mar 27 
 21:19:03 2007
 @@ -600,11 +600,10 @@
assert(V  No Value?);
assert(Depth = 6  Limit Search Depth);
uint32_t BitWidth = Mask.getBitWidth();
 -  const IntegerType *VTy = castIntegerType(V-getType());
 -  assert(VTy-getBitWidth() == BitWidth 
 +  assert(castIntegerType(V-getType())-getBitWidth() == BitWidth 
   KnownZero.getBitWidth() == BitWidth  
   KnownOne.getBitWidth() == BitWidth 
 - VTy, Mask, KnownOne and KnownZero should have same BitWidth);
 + V, Mask, KnownOne and KnownZero should have same BitWidth);
if (ConstantInt *CI = dyn_castConstantInt(V)) {
  // We know all of the bits for a constant!
  KnownOne = CI-getValue()  Mask;
 @@ -685,8 +684,11 @@
  // All these have integer operands
  uint32_t SrcBitWidth = 
castIntegerType(I-getOperand(0)-getType())-getBitWidth();
 -ComputeMaskedBits(I-getOperand(0), APInt(Mask).zext(SrcBitWidth), 
 -  KnownZero.zext(SrcBitWidth), KnownOne.zext(SrcBitWidth), Depth+1);
 +APInt MaskIn(Mask);
 +MaskIn.zext(SrcBitWidth);
 +KnownZero.zext(SrcBitWidth);
 +KnownOne.zext(SrcBitWidth);
 +ComputeMaskedBits(I-getOperand(0), MaskIn, KnownZero, KnownOne, 
 Depth+1);
  KnownZero.trunc(BitWidth);
  KnownOne.trunc(BitWidth);
  return;
 @@ -703,43 +705,40 @@
  // Compute the bits in the result that are not present in the input.
  const IntegerType *SrcTy = 
 castIntegerType(I-getOperand(0)-getType());
  uint32_t SrcBitWidth = SrcTy-getBitWidth();
 -APInt NewBits(APInt::getHighBitsSet(BitWidth, BitWidth - SrcBitWidth));

 -ComputeMaskedBits(I-getOperand(0), APInt(Mask).trunc(SrcBitWidth), 
 -  KnownZero.trunc(SrcBitWidth), KnownOne.trunc(SrcBitWidth), Depth+1);
 +APInt MaskIn(Mask);
 +MaskIn.trunc(SrcBitWidth);
 +KnownZero.trunc(SrcBitWidth);
 +KnownOne.trunc(SrcBitWidth);
 +ComputeMaskedBits(I-getOperand(0), MaskIn, KnownZero, KnownOne, 
 Depth+1);
  assert((KnownZero  KnownOne) == 0  Bits known to be one AND zero?); 
  // The top bits are known to be zero.
  KnownZero.zext(BitWidth);
  KnownOne.zext(BitWidth);
 -KnownZero |= NewBits;
 +KnownZero |= APInt::getHighBitsSet(BitWidth, BitWidth - SrcBitWidth);
  return;
}
case Instruction::SExt: {
  // Compute the bits in the result that are not present in the input.
  const IntegerType *SrcTy = 
 castIntegerType(I-getOperand(0)-getType());
  uint32_t SrcBitWidth = SrcTy-getBitWidth();
 -APInt NewBits(APInt::getHighBitsSet(BitWidth, BitWidth - SrcBitWidth));

 -ComputeMaskedBits(I-getOperand(0), APInt(Mask).trunc(SrcBitWidth), 
 -  KnownZero.trunc(SrcBitWidth), KnownOne.trunc(SrcBitWidth), Depth+1);
 +APInt MaskIn(Mask); 
 +MaskIn.trunc(SrcBitWidth);
 +KnownZero.trunc(SrcBitWidth);
 +KnownOne.trunc(SrcBitWidth);
 +ComputeMaskedBits(I-getOperand(0), MaskIn, KnownZero, KnownOne, 
 Depth+1);
  assert((KnownZero  KnownOne) == 0  Bits known to be one AND zero?); 
  KnownZero.zext(BitWidth);
  KnownOne.zext(BitWidth);
  
  // If the sign bit of the input is known set or clear, then we know the
  // top bits of the result.
 -APInt InSignBit(APInt::getSignBit(SrcTy-getBitWidth()));
 -InSignBit.zext(BitWidth);
 -if ((KnownZero  InSignBit) != 0) {  // Input sign bit known zero
 +APInt NewBits(APInt::getHighBitsSet(BitWidth, BitWidth - SrcBitWidth));
 +if (KnownZero[SrcBitWidth-1]) // Input sign bit known zero

This doesn't look correct nor efficient to me. It should be testing for
only the sign bit. YOu need an  not an |.  You're trying to determine
if the sign bit of the SrcTy is set in KnownZero, right? So, why not:

   if (KnownZero.get(SrcBitWidth-1))

?

KnownZero |= NewBits;
 -  KnownOne = ~NewBits;
 -} else if ((KnownOne  InSignBit) != 0) {// Input sign bit known set
 +else if (KnownOne[SrcBitWidth-1])   // Input sign bit known set

Same issue as above.

KnownOne |= 

[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-03-27 Thread Zhou Sheng


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.701 - 1.702
---
Log message:

Use UnknownBIts[BitWidth-1] instead of UnknownBIts  SignBits.


---
Diffs of the changes:  (+1 -1)

 InstructionCombining.cpp |2 +-
 1 files changed, 1 insertion(+), 1 deletion(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.701 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.702
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.701   Tue Mar 27 
22:02:21 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Wed Mar 28 00:15:57 2007
@@ -851,7 +851,7 @@
   Min = KnownOne;
   Max = KnownOne|UnknownBits;
   
-  if ((SignBit  UnknownBits) != 0) { // Sign bit is unknown
+  if (UnknownBits[BitWidth-1]) { // Sign bit is unknown
 Min |= SignBit;
 Max = ~SignBit;
   }



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


Re: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-03-27 Thread Reid Spencer
Sheng, 

A correction to my last email ..

On Tue, 2007-03-27 at 22:13 -0700, Reid Spencer wrote:
   // If the sign bit of the input is known set or clear, then we know the
   // top bits of the result.
  -APInt InSignBit(APInt::getSignBit(SrcTy-getBitWidth()));
  -InSignBit.zext(BitWidth);
  -if ((KnownZero  InSignBit) != 0) {  // Input sign bit known 
  zero
  +APInt NewBits(APInt::getHighBitsSet(BitWidth, BitWidth - SrcBitWidth));
  +if (KnownZero[SrcBitWidth-1]) // Input sign bit known zero
 
 This doesn't look correct nor efficient to me. It should be testing for
 only the sign bit. YOu need an  not an |.  You're trying to determine
 if the sign bit of the SrcTy is set in KnownZero, right? So, why not:
 
if (KnownZero.get(SrcBitWidth-1))
 
 ?

My eyes are tired tonight. I didn't see the [...] and thought the [ was
| so please disregard. This looks okay.

 
 KnownZero |= NewBits;
  -  KnownOne = ~NewBits;
  -} else if ((KnownOne  InSignBit) != 0) {// Input sign bit known 
  set
  +else if (KnownOne[SrcBitWidth-1])   // Input sign bit known set
 
 Same issue as above.
 
 KnownOne |= NewBits;
  -  KnownZero = ~NewBits;
  -} else {  // Input sign bit unknown
  -  KnownZero = ~NewBits;
  -  KnownOne = ~NewBits;
  -}
 
 Why did you delete this? What if the sign bit is unknown? (neither known
 one nor known zero).  Please revert.

This however is still a problem. It is quite possible for KnownZero[X]
and KnownOne[X] to both be false.

Reid.
 
   return;
 }
 case Instruction::Shl:
  @@ -760,7 +759,6 @@
   if (ConstantInt *SA = dyn_castConstantInt(I-getOperand(1))) {
 // Compute the new bits that are at the top now.
 uint64_t ShiftAmt = SA-getZExtValue();
  -  APInt HighBits(APInt::getHighBitsSet(BitWidth, ShiftAmt));
 
 // Unsigned shift right.
 APInt Mask2(Mask.shl(ShiftAmt));
  @@ -768,16 +766,16 @@
 assert((KnownZero  KnownOne) == 0Bits known to be one AND 
  zero?); 
 KnownZero = APIntOps::lshr(KnownZero, ShiftAmt);
 KnownOne  = APIntOps::lshr(KnownOne, ShiftAmt);
  -  KnownZero |= HighBits;  // high bits known zero.
  +  // high bits known zero.
  +  KnownZero |= APInt::getHighBitsSet(BitWidth, ShiftAmt);
 return;
   }
   break;
 case Instruction::AShr:
  -// (ushr X, C1)  C2 == 0   iff  (-1  C1)  C2 == 0
  +// (ashr X, C1)  C2 == 0   iff  (-1  C1)  C2 == 0
   if (ConstantInt *SA = dyn_castConstantInt(I-getOperand(1))) {
 // Compute the new bits that are at the top now.
 uint64_t ShiftAmt = SA-getZExtValue();
  -  APInt HighBits(APInt::getHighBitsSet(BitWidth, ShiftAmt));
 
 // Signed shift right.
 APInt Mask2(Mask.shl(ShiftAmt));
  @@ -789,11 +787,11 @@
 // Handle the sign bits and adjust to where it is now in the mask.
 APInt SignBit(APInt::getSignBit(BitWidth).lshr(ShiftAmt));
   
  -  if ((KnownZero  SignBit) != 0) {   // New bits are known zero.
  +  APInt HighBits(APInt::getHighBitsSet(BitWidth, ShiftAmt));
  +  if (KnownZero[BitWidth-ShiftAmt-1])// New bits are known zero.
   KnownZero |= HighBits;
  -  } else if ((KnownOne  SignBit) != 0) { // New bits are known one.
  +  else if (KnownOne[BitWidth-ShiftAmt-1])  // New bits are known one.
   KnownOne |= HighBits;
  -  }
 return;
   }
   break;
  
  
  
  ___
  llvm-commits mailing list
  llvm-commits@cs.uiuc.edu
  http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits

___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-03-26 Thread Reid Spencer


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.692 - 1.693
---
Log message:

Get the number of bits to set in a mask correct for a shl/lshr transform.


---
Diffs of the changes:  (+1 -1)

 InstructionCombining.cpp |2 +-
 1 files changed, 1 insertion(+), 1 deletion(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.692 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.693
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.692   Mon Mar 26 
00:25:00 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Mon Mar 26 12:18:58 2007
@@ -5858,7 +5858,7 @@
   BinaryOperator::createLShr(X, ConstantInt::get(Ty, ShiftDiff));
 InsertNewInstBefore(Shift, I);
 
-APInt Mask(APInt::getLowBitsSet(TypeBits, ShiftAmt2));
+APInt Mask(APInt::getLowBitsSet(TypeBits, TypeBits - ShiftAmt2));
 return BinaryOperator::createAnd(Shift, ConstantInt::get(Mask));
   }
   



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-03-26 Thread Reid Spencer


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.693 - 1.694
---
Log message:

Get better debug output by having modified instructions print both the
original and new instruction. A slight performance hit with ostringstream
but it is only for debug.
Also, clean up an uninitialized variable warning noticed in a release build.


---
Diffs of the changes:  (+10 -2)

 InstructionCombining.cpp |   12 ++--
 1 files changed, 10 insertions(+), 2 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.693 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.694
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.693   Mon Mar 26 
12:18:58 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Mon Mar 26 12:44:01 2007
@@ -57,6 +57,9 @@
 #include llvm/ADT/STLExtras.h
 #include algorithm
 #include set
+#ifndef NDEBUG
+#include sstream
+#endif
 using namespace llvm;
 using namespace llvm::PatternMatch;
 
@@ -3134,7 +3137,7 @@
   // Otherwise, if Mask is 0+1+0+, and if B is known to have the low 0+
   // part, we don't need any explicit masks to take them out of A.  If that
   // is all N is, ignore it.
-  unsigned MB, ME;
+  unsigned MB = 0, ME = 0;
   if (isRunOfOnes(Mask, MB, ME)) {  // begin/end bit of run, inclusive
 uint32_t BitWidth = castIntegerType(RHS-getType())-getBitWidth();
 APInt Mask(APInt::getAllOnesValue(BitWidth));
@@ -9445,6 +9448,10 @@
 }
 
 // Now that we have an instruction, try combining it to simplify it...
+#ifndef NDEBUG
+std::string OrigI;
+#endif
+DEBUG(std::ostringstream SS; I-print(SS); OrigI = SS.str(););
 if (Instruction *Result = visit(*I)) {
   ++NumCombined;
   // Should we replace the old instruction with a new one?
@@ -9483,7 +9490,8 @@
 // Erase the old instruction.
 InstParent-getInstList().erase(I);
   } else {
-DOUT  IC: MOD =   *I;
+DOUT  IC: Mod =   OrigI
+  New =   *I;
 
 // If the instruction was modified, it's possible that it is now dead.
 // if so, remove it.



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


Re: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-03-26 Thread Chris Lattner
 @@ -57,6 +57,9 @@
  #include llvm/ADT/STLExtras.h
  #include algorithm
  #include set
 +#ifndef NDEBUG
 +#include sstream
 +#endif

Please don't conditionally #include files.

Thanks for the patch, making instcombine's debug output nicer would  
be very helpful,

-chris

  using namespace llvm;
  using namespace llvm::PatternMatch;

 @@ -3134,7 +3137,7 @@
// Otherwise, if Mask is 0+1+0+, and if B is known to have  
 the low 0+
// part, we don't need any explicit masks to take them out  
 of A.  If that
// is all N is, ignore it.
 -  unsigned MB, ME;
 +  unsigned MB = 0, ME = 0;
if (isRunOfOnes(Mask, MB, ME)) {  // begin/end bit of run,  
 inclusive
  uint32_t BitWidth = castIntegerType(RHS-getType())- 
 getBitWidth();
  APInt Mask(APInt::getAllOnesValue(BitWidth));
 @@ -9445,6 +9448,10 @@
  }

  // Now that we have an instruction, try combining it to  
 simplify it...
 +#ifndef NDEBUG
 +std::string OrigI;
 +#endif
 +DEBUG(std::ostringstream SS; I-print(SS); OrigI = SS.str(););
  if (Instruction *Result = visit(*I)) {
++NumCombined;
// Should we replace the old instruction with a new one?
 @@ -9483,7 +9490,8 @@
  // Erase the old instruction.
  InstParent-getInstList().erase(I);
} else {
 -DOUT  IC: MOD =   *I;
 +DOUT  IC: Mod =   OrigI
 +  New =   *I;

  // If the instruction was modified, it's possible that it  
 is now dead.
  // if so, remove it.



 ___
 llvm-commits mailing list
 llvm-commits@cs.uiuc.edu
 http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits

___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


Re: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-03-26 Thread Reid Spencer
On Mon, 2007-03-26 at 11:29 -0700, Chris Lattner wrote:
  @@ -57,6 +57,9 @@
   #include llvm/ADT/STLExtras.h
   #include algorithm
   #include set
  +#ifndef NDEBUG
  +#include sstream
  +#endif
 
 Please don't conditionally #include files.

Why? You would get sstream #included in a release build when it isn't
used in a release build.  Seems pointless to me.

 
 Thanks for the patch, making instcombine's debug output nicer would  
 be very helpful,

Yup .. helped verify that the test case I had yesterday was wrong (after
the fix).

Reid.

 
 -chris
 
   using namespace llvm;
   using namespace llvm::PatternMatch;
 
  @@ -3134,7 +3137,7 @@
 // Otherwise, if Mask is 0+1+0+, and if B is known to have  
  the low 0+
 // part, we don't need any explicit masks to take them out  
  of A.  If that
 // is all N is, ignore it.
  -  unsigned MB, ME;
  +  unsigned MB = 0, ME = 0;
 if (isRunOfOnes(Mask, MB, ME)) {  // begin/end bit of run,  
  inclusive
   uint32_t BitWidth = castIntegerType(RHS-getType())- 
  getBitWidth();
   APInt Mask(APInt::getAllOnesValue(BitWidth));
  @@ -9445,6 +9448,10 @@
   }
 
   // Now that we have an instruction, try combining it to  
  simplify it...
  +#ifndef NDEBUG
  +std::string OrigI;
  +#endif
  +DEBUG(std::ostringstream SS; I-print(SS); OrigI = SS.str(););
   if (Instruction *Result = visit(*I)) {
 ++NumCombined;
 // Should we replace the old instruction with a new one?
  @@ -9483,7 +9490,8 @@
   // Erase the old instruction.
   InstParent-getInstList().erase(I);
 } else {
  -DOUT  IC: MOD =   *I;
  +DOUT  IC: Mod =   OrigI
  +  New =   *I;
 
   // If the instruction was modified, it's possible that it  
  is now dead.
   // if so, remove it.
 
 
 
  ___
  llvm-commits mailing list
  llvm-commits@cs.uiuc.edu
  http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
 
 ___
 llvm-commits mailing list
 llvm-commits@cs.uiuc.edu
 http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


signature.asc
Description: This is a digitally signed message part
___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


Re: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-03-26 Thread Chris Lattner

On Mar 26, 2007, at 11:33 AM, Reid Spencer wrote:

 On Mon, 2007-03-26 at 11:29 -0700, Chris Lattner wrote:
 @@ -57,6 +57,9 @@
  #include llvm/ADT/STLExtras.h
  #include algorithm
  #include set
 +#ifndef NDEBUG
 +#include sstream
 +#endif

 Please don't conditionally #include files.

 Why? You would get sstream #included in a release build when it isn't
 used in a release build.  Seems pointless to me.

Because someone will later add code to instcombine that uses sstream  
that isn't itself guarded by the NDEBUG ifdef.  Suddenly the release  
builds start failing.

-Chris
___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-03-26 Thread Chris Lattner


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.694 - 1.695
---
Log message:

eliminate use of std::set


---
Diffs of the changes:  (+4 -6)

 InstructionCombining.cpp |   10 --
 1 files changed, 4 insertions(+), 6 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.694 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.695
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.694   Mon Mar 26 
12:44:01 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Mon Mar 26 15:40:50 2007
@@ -56,10 +56,7 @@
 #include llvm/ADT/Statistic.h
 #include llvm/ADT/STLExtras.h
 #include algorithm
-#include set
-#ifndef NDEBUG
 #include sstream
-#endif
 using namespace llvm;
 using namespace llvm::PatternMatch;
 
@@ -7808,12 +7805,13 @@
 
 /// DeadPHICycle - Return true if this PHI node is only used by a PHI node 
cycle
 /// that is dead.
-static bool DeadPHICycle(PHINode *PN, std::setPHINode* PotentiallyDeadPHIs) 
{
+static bool DeadPHICycle(PHINode *PN,
+ SmallPtrSetPHINode*, 16 PotentiallyDeadPHIs) {
   if (PN-use_empty()) return true;
   if (!PN-hasOneUse()) return false;
 
   // Remember this node, and if we find the cycle, return.
-  if (!PotentiallyDeadPHIs.insert(PN).second)
+  if (!PotentiallyDeadPHIs.insert(PN))
 return true;
 
   if (PHINode *PU = dyn_castPHINode(PN-use_back()))
@@ -7844,7 +7842,7 @@
   if (PN.hasOneUse()) {
 Instruction *PHIUser = castInstruction(PN.use_back());
 if (PHINode *PU = dyn_castPHINode(PHIUser)) {
-  std::setPHINode* PotentiallyDeadPHIs;
+  SmallPtrSetPHINode*, 16 PotentiallyDeadPHIs;
   PotentiallyDeadPHIs.insert(PN);
   if (DeadPHICycle(PU, PotentiallyDeadPHIs))
 return ReplaceInstUsesWith(PN, UndefValue::get(PN.getType()));



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-03-26 Thread Reid Spencer


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.695 - 1.696
---
Log message:

For PR1271: http://llvm.org/PR1271 :
Fix another incorrectly converted shift mask.


---
Diffs of the changes:  (+1 -1)

 InstructionCombining.cpp |2 +-
 1 files changed, 1 insertion(+), 1 deletion(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.695 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.696
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.695   Mon Mar 26 
15:40:50 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Mon Mar 26 18:45:51 2007
@@ -5887,7 +5887,7 @@
   BinaryOperator::createShl(X, ConstantInt::get(Ty, ShiftDiff));
 InsertNewInstBefore(Shift, I);
 
-APInt Mask(APInt::getHighBitsSet(TypeBits, TypeBits - ShiftAmt2));
+APInt Mask(APInt::getLowBitsSet(TypeBits, TypeBits - ShiftAmt2));
 return BinaryOperator::createAnd(Shift, ConstantInt::get(Mask));
   }
   



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-03-26 Thread Reid Spencer


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.696 - 1.697
---
Log message:

Implement some minor review feedback.


---
Diffs of the changes:  (+3 -3)

 InstructionCombining.cpp |6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.696 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.697
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.696   Mon Mar 26 
18:45:51 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Mon Mar 26 18:58:26 2007
@@ -2455,7 +2455,7 @@
   // Check to see if this is an unsigned division with an exact power of 2,
   // if so, convert to a right shift.
   if (ConstantInt *C = dyn_castConstantInt(Op1)) {
-if (!C-isZero()  C-getValue().isPowerOf2())  // Don't break X / 0
+if (C-getValue().isPowerOf2())  // 0 not included in isPowerOf2
   return BinaryOperator::createLShr(Op0, 
ConstantInt::get(Op0-getType(), C-getValue().logBase2()));
   }
@@ -3149,7 +3149,7 @@
 // If the AndRHS is a power of two minus one (0+1+), and NMask == 0
 if ((Mask-getValue().countLeadingZeros() + 
  Mask-getValue().countPopulation()) == Mask-getValue().getBitWidth()
- And(N, Mask)-isNullValue())
+ And(N, Mask)-isZero())
   break;
 return 0;
   }
@@ -3180,7 +3180,7 @@
 APInt KnownZero(BitWidth, 0), KnownOne(BitWidth, 0);
 if (SimplifyDemandedBits(I, APInt::getAllOnesValue(BitWidth),
  KnownZero, KnownOne))
-return I;
+  return I;
   } else {
 if (ConstantVector *CP = dyn_castConstantVector(Op1)) {
   if (CP-isAllOnesValue())



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


Re: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-03-25 Thread Chris Lattner
 Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
 diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.687  
 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.688
 --- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.687 Sun  
 Mar 25 00:01:29 2007
 +++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp   Sun Mar 25  
 00:33:51 2007
 @@ -540,8 +540,9 @@
if (I-getOpcode() == Instruction::Shl)
  if ((CST = dyn_castConstantInt(I-getOperand(1 {
// The multiplier is really 1  CST.
 -  Constant *One = ConstantInt::get(V-getType(), 1);
 -  CST = castConstantInt(ConstantExpr::getShl(One, CST));
 +  APInt Multiplier(V-getType()-getPrimitiveSizeInBits(),  
 0);
 +  Multiplier.set(CST-getZExtValue()); // set bit is == 1  
  CST

This doesn't seem safe.  Won't getZextValue assert if CST is  64 bits?

Also, I don't understand the gymnastics you're doing with Multiplier.

 +  CST = ConstantInt::get(Multiplier);
return I-getOperand(0);
  }
  }
 @@ -558,14 +559,31 @@
return false;
  }

 +/// AddOne - Add one to a ConstantInt
  static ConstantInt *AddOne(ConstantInt *C) {
 +  APInt One(C-getType()-getPrimitiveSizeInBits(),1);
 +  return ConstantInt::get(C-getValue() + One);
  }
 +/// SubOne - Subtract one from a ConstantInt
  static ConstantInt *SubOne(ConstantInt *C) {

Shouldn't these use ++/-- on APInt?  That seems more efficient.

 @@ -2188,14 +2203,12 @@

ConstantInt *C1;
if (Value *X = dyn_castFoldableMul(Op0, C1)) {
 -if (X == Op1) { // X*C - X -- X * (C-1)
 -  Constant *CP1 = ConstantExpr::getSub(C1, ConstantInt::get 
 (I.getType(),1));
 -  return BinaryOperator::createMul(Op1, CP1);
 -}
 +if (X == Op1)  // X*C - X -- X * (C-1)
 +  return BinaryOperator::createMul(Op1, SubOne(C1));

I like this set of changes, much cleaner.

-Chris
___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


Re: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-03-25 Thread Chris Lattner

On Mar 25, 2007, at 12:10 PM, Reid Spencer wrote:

 On Sun, 2007-03-25 at 11:55 -0700, Chris Lattner wrote:
 Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
 diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.687
 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.688
 --- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.687   Sun
 Mar 25 00:01:29 2007
 +++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Sun Mar 25
 00:33:51 2007
 @@ -540,8 +540,9 @@
if (I-getOpcode() == Instruction::Shl)
  if ((CST = dyn_castConstantInt(I-getOperand(1 {
// The multiplier is really 1  CST.
 -  Constant *One = ConstantInt::get(V-getType(), 1);
 -  CST = castConstantInt(ConstantExpr::getShl(One, CST));
 +  APInt Multiplier(V-getType()-getPrimitiveSizeInBits(),
 0);
 +  Multiplier.set(CST-getZExtValue()); // set bit is == 1
  CST

 This doesn't seem safe.  Won't getZextValue assert if CST is  64  
 bits?

 The same comment you made about huge shift values applies here. I was
 assuming the shift amount would always fit in 64-bits (32, really),  
 but
 as you mentioned before, it could be some huge value. Will fix.  In
 practice, this is quite unlikely to cause a problem.

Right.

 Also, I don't understand the gymnastics you're doing with Multiplier.

 Just trying to get rid of an expensive ConstantExpr::getShl. In  
 addition
 to the ConstantExpr overhead, the resulting Shl on an APInt isn't  
 super
 cheap, even for the = 64 bits case. Setting a bit is pretty cheap.  
 But,
 I'll probably just revert to get over the huge value issue.

k


 +/// SubOne - Subtract one from a ConstantInt
  static ConstantInt *SubOne(ConstantInt *C) {

 Shouldn't these use ++/-- on APInt?  That seems more efficient.

 I should really have these functions declare the parameter  
 constant. We
 don't want to increment the APInt inside C. Either way, a copy of the
 value is being made.

Right.  ConstantInt's are immutable, so it doesn't really need to be  
marked const.  I'm saying that the implementation of these methods  
shouldn't build a 1 apint, then add it.  Instead, it should just  
increment an apint with ++.



 @@ -2188,14 +2203,12 @@

ConstantInt *C1;
if (Value *X = dyn_castFoldableMul(Op0, C1)) {
 -if (X == Op1) { // X*C - X -- X * (C-1)
 -  Constant *CP1 = ConstantExpr::getSub(C1, ConstantInt::get
 (I.getType(),1));
 -  return BinaryOperator::createMul(Op1, CP1);
 -}
 +if (X == Op1)  // X*C - X -- X * (C-1)
 +  return BinaryOperator::createMul(Op1, SubOne(C1));

 I like this set of changes, much cleaner.

 This was the real intent .. makes the code more readable and a little
 bit faster too.

Yep, thanks again,

-Chris
___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


Re: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-03-25 Thread Reid Spencer
On Sun, 2007-03-25 at 12:25 -0700, Chris Lattner wrote:
 
  +/// SubOne - Subtract one from a ConstantInt
   static ConstantInt *SubOne(ConstantInt *C) {
 
  Shouldn't these use ++/-- on APInt?  That seems more efficient.
 
  I should really have these functions declare the parameter  
  constant. We
  don't want to increment the APInt inside C. Either way, a copy of the
  value is being made.
 
 Right.  ConstantInt's are immutable, so it doesn't really need to be  
 marked const.  I'm saying that the implementation of these methods  
 shouldn't build a 1 apint, then add it.  Instead, it should just  
 increment an apint with ++.

Yup. I've already changed it to:

static ConstantInt *AddOne(ConstantInt *C) {
  APInt Val(C-getValue());
  return ConstantInt::get(++Val);
}

Reid.



signature.asc
Description: This is a digitally signed message part
___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


Re: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-03-25 Thread Chris Lattner
 Right.  ConstantInt's are immutable, so it doesn't really need to be
 marked const.  I'm saying that the implementation of these methods
 shouldn't build a 1 apint, then add it.  Instead, it should just
 increment an apint with ++.

 Yup. I've already changed it to:

 static ConstantInt *AddOne(ConstantInt *C) {
   APInt Val(C-getValue());
   return ConstantInt::get(++Val);
 }

Beautiful,

-Chris
___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-03-25 Thread Reid Spencer


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.688 - 1.689
---
Log message:

Some cleanup from review:
* Don't assume shift amounts are = 64 bits
* Avoid creating an extra APInt in SubOne and AddOne by using -- and ++
* Add another use of getLowBitsSet
* Convert a series of if statements to a switch


---
Diffs of the changes:  (+18 -16)

 InstructionCombining.cpp |   34 ++
 1 files changed, 18 insertions(+), 16 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.688 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.689
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.688   Sun Mar 25 
00:33:51 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Sun Mar 25 14:55:33 2007
@@ -540,9 +540,8 @@
   if (I-getOpcode() == Instruction::Shl)
 if ((CST = dyn_castConstantInt(I-getOperand(1 {
   // The multiplier is really 1  CST.
-  APInt Multiplier(V-getType()-getPrimitiveSizeInBits(), 0);
-  Multiplier.set(CST-getZExtValue()); // set bit is == 1  CST
-  CST = ConstantInt::get(Multiplier);
+  Constant *One = ConstantInt::get(V-getType(), 1);
+  CST = castConstantInt(ConstantExpr::getShl(One, CST));
   return I-getOperand(0);
 }
 }
@@ -561,13 +560,13 @@
 
 /// AddOne - Add one to a ConstantInt
 static ConstantInt *AddOne(ConstantInt *C) {
-  APInt One(C-getType()-getPrimitiveSizeInBits(),1);
-  return ConstantInt::get(C-getValue() + One);
+  APInt Val(C-getValue());
+  return ConstantInt::get(++Val);
 }
 /// SubOne - Subtract one from a ConstantInt
 static ConstantInt *SubOne(ConstantInt *C) {
-  APInt One(C-getType()-getPrimitiveSizeInBits(),1);
-  return ConstantInt::get(C-getValue() - One);
+  APInt Val(C-getValue());
+  return ConstantInt::get(--Val);
 }
 /// Add - Add two ConstantInts together
 static ConstantInt *Add(ConstantInt *C1, ConstantInt *C2) {
@@ -752,7 +751,7 @@
   assert((KnownZero  KnownOne) == 0  Bits known to be one AND zero?); 
   KnownZero = ShiftAmt;
   KnownOne  = ShiftAmt;
-  KnownZero |= APInt(BitWidth, 1ULL).shl(ShiftAmt)-1;  // low bits known 0
+  KnownZero |= APInt::getLowBitsSet(BitWidth, ShiftAmt); // low bits known 0
   return;
 }
 break;
@@ -4654,14 +4653,17 @@
 // appropriate icmp lt or icmp gt instruction.  Since the border cases have
 // already been handled above, this requires little checking.
 //
-if (I.getPredicate() == ICmpInst::ICMP_ULE)
-  return new ICmpInst(ICmpInst::ICMP_ULT, Op0, AddOne(CI));
-if (I.getPredicate() == ICmpInst::ICMP_SLE)
-  return new ICmpInst(ICmpInst::ICMP_SLT, Op0, AddOne(CI));
-if (I.getPredicate() == ICmpInst::ICMP_UGE)
-  return new ICmpInst( ICmpInst::ICMP_UGT, Op0, SubOne(CI));
-if (I.getPredicate() == ICmpInst::ICMP_SGE)
-  return new ICmpInst(ICmpInst::ICMP_SGT, Op0, SubOne(CI));
+switch (I.getPredicate()) {
+  default: break;
+  case ICmpInst::ICMP_ULE: 
+return new ICmpInst(ICmpInst::ICMP_ULT, Op0, AddOne(CI));
+  case ICmpInst::ICMP_SLE:
+return new ICmpInst(ICmpInst::ICMP_SLT, Op0, AddOne(CI));
+  case ICmpInst::ICMP_UGE:
+return new ICmpInst( ICmpInst::ICMP_UGT, Op0, SubOne(CI));
+  case ICmpInst::ICMP_SGE:
+return new ICmpInst(ICmpInst::ICMP_SGT, Op0, SubOne(CI));
+}
 
 // See if we can fold the comparison based on bits known to be zero or one
 // in the input.



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


Re: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-03-25 Thread Chris Lattner
 Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
 diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.688  
 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.689
 --- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.688 Sun  
 Mar 25 00:33:51 2007
 +++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp   Sun Mar 25  
 14:55:33 2007
 @@ -540,9 +540,8 @@
if (I-getOpcode() == Instruction::Shl)
  if ((CST = dyn_castConstantInt(I-getOperand(1 {
// The multiplier is really 1  CST.
 -  APInt Multiplier(V-getType()-getPrimitiveSizeInBits(),  
 0);
 -  Multiplier.set(CST-getZExtValue()); // set bit is == 1  
  CST
 -  CST = ConstantInt::get(Multiplier);
 +  Constant *One = ConstantInt::get(V-getType(), 1);
 +  CST = castConstantInt(ConstantExpr::getShl(One, CST));

This is doing arithmetic with constant expr :(.  Why not something like:

ConstantInt::get(APInt(bitwidth, 1).shl(CST-getValue()))

or something?

-Chris
___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-03-25 Thread Chris Lattner


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.689 - 1.690
---
Log message:

implement Transforms/InstCombine/cast2.ll:test3 and PR1263: 
http://llvm.org/PR1263 


---
Diffs of the changes:  (+21 -1)

 InstructionCombining.cpp |   22 +-
 1 files changed, 21 insertions(+), 1 deletion(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.689 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.690
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.689   Sun Mar 25 
14:55:33 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Sun Mar 25 15:43:09 2007
@@ -7896,10 +7896,22 @@
   if (GEP.getNumOperands() == 2  HasZeroPointerIndex)
 return ReplaceInstUsesWith(GEP, PtrOp);
 
+  // Keep track of whether all indices are zero constants integers.
+  bool AllZeroIndices = true;
+  
   // Eliminate unneeded casts for indices.
   bool MadeChange = false;
+  
   gep_type_iterator GTI = gep_type_begin(GEP);
-  for (unsigned i = 1, e = GEP.getNumOperands(); i != e; ++i, ++GTI)
+  for (unsigned i = 1, e = GEP.getNumOperands(); i != e; ++i, ++GTI) {
+// Track whether this GEP has all zero indices, if so, it doesn't move the
+// input pointer, it just changes its type.
+if (AllZeroIndices) {
+  if (ConstantInt *CI = dyn_castConstantInt(GEP.getOperand(i)))
+AllZeroIndices = CI-isNullValue();
+  else
+AllZeroIndices = false;
+}
 if (isaSequentialType(*GTI)) {
   if (CastInst *CI = dyn_castCastInst(GEP.getOperand(i))) {
 if (CI-getOpcode() == Instruction::ZExt ||
@@ -7929,8 +7941,16 @@
   MadeChange = true;
 }
 }
+  }
   if (MadeChange) return GEP;
 
+  // If this GEP instruction doesn't move the pointer, and if the input operand
+  // is a bitcast of another pointer, just replace the GEP with a bitcast of 
the
+  // real input to the dest type.
+  if (AllZeroIndices  isaBitCastInst(GEP.getOperand(0)))
+return new BitCastInst(castBitCastInst(GEP.getOperand(0))-getOperand(0),
+   GEP.getType());
+
   // Combine Indices - If the source pointer to this getelementptr instruction
   // is a getelementptr instruction, combine the indices of the two
   // getelementptr instructions into a single instruction.



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-03-25 Thread Reid Spencer


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.690 - 1.691
---
Log message:

For PR1271: http://llvm.org/PR1271 :
Remove a use of getLowBitsSet that caused the mask used for replacement of
shl/lshr pairs with an AND instruction to be computed incorrectly. Its not
clear exactly why this is the case. This solves the disappearing shifts
problem, but it doesn't fix Regression/C/2003-05-21-UnionBitFields. It 
seems there is more going on.


---
Diffs of the changes:  (+11 -12)

 InstructionCombining.cpp |   23 +++
 1 files changed, 11 insertions(+), 12 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.690 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.691
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.690   Sun Mar 25 
15:43:09 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Sun Mar 25 16:11:44 2007
@@ -595,7 +595,7 @@
 /// optimized based on the contradictory assumption that it is non-zero.
 /// Because instcombine aggressively folds operations with undef args anyway,
 /// this won't lose us code quality.
-static void ComputeMaskedBits(Value *V, const APInt Mask, APInt KnownZero, 
+static void ComputeMaskedBits(Value *V, const APInt Mask, APInt KnownZero, 
   APInt KnownOne, unsigned Depth = 0) {
   assert(V  No Value?);
   assert(Depth = 6  Limit Search Depth);
@@ -1200,7 +1200,7 @@
 // Figure out what the input bits are.  If the top bits of the and result
 // are not demanded, then the add doesn't demand them from its input
 // either.
-unsigned NLZ = DemandedMask.countLeadingZeros();
+uint32_t NLZ = DemandedMask.countLeadingZeros();
   
 // If there is a constant on the RHS, there are a variety of xformations
 // we can do.
@@ -1296,7 +1296,7 @@
 if ((DemandedMask  APInt::getSignBit(BitWidth)) == 0) {
   // Right fill the mask of bits for this SUB to demand the most
   // significant bit and all those below it.
-  uint32_t NLZ = DemandedMask.countLeadingZeros();
+  unsigned NLZ = DemandedMask.countLeadingZeros();
   APInt DemandedFromOps(APInt::getAllOnesValue(BitWidth).lshr(NLZ));
   if (SimplifyDemandedBits(I-getOperand(0), DemandedFromOps,
LHSKnownZero, LHSKnownOne, Depth+1))
@@ -4877,8 +4877,8 @@
 if (LHSI-hasOneUse()) {
   // Otherwise strength reduce the shift into an and.
   unsigned ShAmtVal = (unsigned)ShAmt-getZExtValue();
-  Constant *Mask = ConstantInt::get(APInt::getLowBitsSet(TypeBits, 
-  TypeBits - 
ShAmtVal));
+  uint64_t Val = (1ULL  (TypeBits-ShAmtVal))-1;
+  Constant *Mask = ConstantInt::get(CI-getType(), Val);
 
   Instruction *AndI =
 BinaryOperator::createAnd(LHSI-getOperand(0),
@@ -5809,7 +5809,7 @@
 if (ShiftAmt1 == ShiftAmt2) {
   // If we have ((X ? C)  C), turn this into X  (-1  C).
   if (I.getOpcode() == Instruction::Shl) {
-APInt Mask(Ty-getMask().shl(ShiftAmt1));
+APInt Mask(APInt::getHighBitsSet(TypeBits, TypeBits - ShiftAmt1));
 return BinaryOperator::createAnd(X, ConstantInt::get(Mask));
   }
   // If we have ((X  C) u C), turn this into X  (-1 u C).
@@ -5847,9 +5847,8 @@
   BinaryOperator::createShl(X, ConstantInt::get(Ty, ShiftDiff));
 InsertNewInstBefore(Shift, I);
 
-ConstantInt *Mask = ConstantInt::get(
-APInt::getHighBitsSet(TypeBits, TypeBits - ShiftAmt2));
-return BinaryOperator::createAnd(Shift, Mask);
+APInt Mask(APInt::getHighBitsSet(TypeBits, TypeBits - ShiftAmt2));
+return BinaryOperator::createAnd(Shift, ConstantInt::get(Mask));
   }
   
   // (X  C1) u C2  -- X u (C2-C1)  (-1  C2)
@@ -5859,7 +5858,7 @@
   BinaryOperator::createLShr(X, ConstantInt::get(Ty, ShiftDiff));
 InsertNewInstBefore(Shift, I);
 
-APInt Mask(Ty-getMask().lshr(ShiftAmt2));
+APInt Mask(APInt::getHighBitsSet(TypeBits, TypeBits - ShiftAmt2));
 return BinaryOperator::createAnd(Shift, ConstantInt::get(Mask));
   }
   
@@ -5877,7 +5876,7 @@
  ConstantInt::get(Ty, ShiftDiff));
 InsertNewInstBefore(Shift, I);
 
-APInt Mask(Ty-getMask().shl(ShiftAmt2));
+APInt Mask(APInt::getHighBitsSet(TypeBits, TypeBits - ShiftAmt2));
 return BinaryOperator::createAnd(Shift, ConstantInt::get(Mask));
   }
   
@@ -5888,7 +5887,7 @@
   BinaryOperator::createShl(X, ConstantInt::get(Ty, ShiftDiff));
 InsertNewInstBefore(Shift, I);
 
-APInt Mask(Ty-getMask().lshr(ShiftAmt2));
+APInt Mask(APInt::getHighBitsSet(TypeBits, TypeBits - ShiftAmt2));
 return 

[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-03-25 Thread Reid Spencer


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.691 - 1.692
---
Log message:

For PR1271: http://llvm.org/PR1271 :
Fix SingleSource/Regression/C/2003-05-21-UnionBitFields.c by changing a
getHighBitsSet call to getLowBitsSet call that was incorrectly converted
from the original lshr constant expression.


---
Diffs of the changes:  (+1 -1)

 InstructionCombining.cpp |2 +-
 1 files changed, 1 insertion(+), 1 deletion(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.691 
llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.692
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.691   Sun Mar 25 
16:11:44 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Mon Mar 26 00:25:00 2007
@@ -5858,7 +5858,7 @@
   BinaryOperator::createLShr(X, ConstantInt::get(Ty, ShiftDiff));
 InsertNewInstBefore(Shift, I);
 
-APInt Mask(APInt::getHighBitsSet(TypeBits, TypeBits - ShiftAmt2));
+APInt Mask(APInt::getLowBitsSet(TypeBits, ShiftAmt2));
 return BinaryOperator::createAnd(Shift, ConstantInt::get(Mask));
   }
   



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


Re: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-03-24 Thread Chris Lattner

 Add an APInt version of SimplifyDemandedBits.

 Patch by Zhou Sheng.

Commenting on the version from mainline, comments preceeded with ***'s:


static void ComputeMaskedBits(Value *V, APInt Mask, APInt KnownZero,
*** Mask should be passed by const.


bool InstCombiner::SimplifyDemandedBits(Value *V, APInt DemandedMask,
*** Plz pass APInt's by const, not by-value.
 APInt KnownZero, APInt  
KnownOne,
 unsigned Depth) {

...

   Instruction *I = dyn_castInstruction(V);
   if (!I) return false;// Only analyze instructions.

   DemandedMask = APInt::getAllOnesValue(BitWidth);
*** This = is dead.

   APInt LHSKnownZero(BitWidth, 0), LHSKnownOne(BitWidth, 0);
   APInt RHSKnownZero = KnownZero, RHSKnownOne = KnownOne;
*** What is the point of the RHSKnownZero/RHSKnownOne references, plz  
drop them.

   switch (I-getOpcode()) {
...
   case Instruction::Trunc: {
 uint32_t truncBf =
   castIntegerType(I-getOperand(0)-getType())-getBitWidth();
 if (SimplifyDemandedBits(I-getOperand(0), DemandedMask.zext 
(truncBf),
 RHSKnownZero.zext(truncBf), RHSKnownOne.zext(truncBf), Depth 
+1))
*** Plz move the calls to zext out of line.
   return true;
 DemandedMask.trunc(BitWidth);
 RHSKnownZero.trunc(BitWidth);
 RHSKnownOne.trunc(BitWidth);
 assert((RHSKnownZero  RHSKnownOne) == 0 
Bits known to be one AND zero?);
 break;
   }

   case Instruction::ZExt: {
 // Compute the bits in the result that are not present in the  
input.
 const IntegerType *SrcTy = castIntegerType(I-getOperand(0)- 
 getType());
 APInt NewBits(APInt::getAllOnesValue(BitWidth).shl(SrcTy- 
 getBitWidth()));
*** This idiom occurs in many places, it should be a new  
APInt::getHighBitsSet(width,numbits) method.

 DemandedMask = SrcTy-getMask().zext(BitWidth);
*** This should truncate DemandedMask then 'and' it.

 uint32_t zextBf = SrcTy-getBitWidth();
 if (SimplifyDemandedBits(I-getOperand(0), DemandedMask.trunc 
(zextBf),
   RHSKnownZero.trunc(zextBf), RHSKnownOne.trunc(zextBf),  
Depth+1))
*** Truncs out of line plz.
   return true;
   }
   case Instruction::SExt: {
 // Compute the bits in the result that are not present in the  
input.
 const IntegerType *SrcTy = castIntegerType(I-getOperand(0)- 
 getType());
 APInt NewBits(APInt::getAllOnesValue(BitWidth).shl(SrcTy- 
 getBitWidth()));
*** Should use APInt::getHighBitsSet.

 // Get the sign bit for the source type
 APInt InSignBit(APInt::getSignBit(SrcTy-getPrimitiveSizeInBits 
()));
 InSignBit.zext(BitWidth);
 APInt InputDemandedBits = DemandedMask 
   SrcTy-getMask().zext(BitWidth);
*** The getMask().zext stuff should get 'APInt::getLowBitsSet(...)'.
..
 uint32_t sextBf = SrcTy-getBitWidth();
 if (SimplifyDemandedBits(I-getOperand(0),  
InputDemandedBits.trunc(sextBf),
   RHSKnownZero.trunc(sextBf), RHSKnownOne.trunc(sextBf),  
Depth+1))
*** Plz don't nest the trunc calls.
   return true;

   case Instruction::Add: {
...
   // If the top bit of the output is demanded, demand everything  
from the
   // input.  Otherwise, we demand all the input bits except NLZ  
top bits.
   APInt InDemandedBits(APInt::getAllOnesValue(BitWidth).lshr(NLZ));
*** Should be APInt::getLowBitsSet.

...
   bool CarryIn = false;
   APInt CarryBits(BitWidth, 0);
   const uint64_t *LHSKnownZeroRawVal = LHSKnownZero.getRawData(),
  *RHSRawVal = RHSVal.getRawData();
   for (uint32_t i = 0; i != RHSVal.getNumWords(); ++i) {
 uint64_t AddVal = ~LHSKnownZeroRawVal[i] + RHSRawVal[i],
  XorVal = ~LHSKnownZeroRawVal[i] ^ RHSRawVal[i];
 uint64_t WordCarryBits = AddVal ^ XorVal + CarryIn;
 if (AddVal  RHSRawVal[i])
   CarryIn = true;
 else
   CarryIn = false;
 CarryBits.setWordToValue(i, WordCarryBits);
   }
*** Why aren't you doing this in terms of APInt operations?
...
   // If the high-bits of this ADD are not demanded, then it does  
not demand
   // the high bits of its LHS or RHS.
   if ((DemandedMask  APInt::getSignBit(BitWidth)) == 0) {
*** This seems like it should be: if (DemandedMask[BitWidth-1] == 0)  
{.  Likewise in other places, grep for getSignBit to find them.
 // Right fill the mask of bits for this ADD to demand the most
 // significant bit and all those below it.
 APInt DemandedFromOps = APInt::getAllOnesValue(BitWidth).lshr 
(NLZ);
*** Use APInt::getLowBitsSet.

...

   case Instruction::Sub:
 // If the high-bits of this SUB are not demanded, then it does  
not demand
 // the high bits of its LHS or RHS.
 if ((DemandedMask  APInt::getSignBit(BitWidth)) == 0) {
*** Use operator[]
   // Right fill the mask of bits for this SUB to demand the most
   // significant bit and all those below it.
 

Re: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-03-24 Thread Chris Lattner

On Mar 24, 2007, at 8:34 AM, Zhou Sheng wrote:



 Changes in directory llvm/lib/Transforms/Scalar:

 InstructionCombining.cpp updated: 1.682 - 1.683
 ---
 Log message:

 Make some codes more efficient.

 @@ -5813,7 +5816,6 @@
case 16 : SExtType = Type::Int16Ty; break;
case 32 : SExtType = Type::Int32Ty; break;
case 64 : SExtType = Type::Int64Ty; break;
 -  case 128: SExtType = IntegerType::get(128); break;
default: break;
}
if (SExtType) {

why did you remove this?

 @@ -5833,7 +5835,7 @@
BinaryOperator::createShl(X, ConstantInt::get(Ty,  
 ShiftDiff));
  InsertNewInstBefore(Shift, I);

 -APInt Mask(APInt::getAllOnesValue(TypeBits).shl(ShiftAmt2));
 +APInt Mask(Ty-getMask().shl(ShiftAmt2));

You touched many instances of this.  Please make a new  
APInt::getHighBits method.

-Chris
___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


Re: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-03-24 Thread Reid Spencer
On Sat, 2007-03-24 at 10:06 -0700, Chris Lattner wrote:
 On Mar 24, 2007, at 8:34 AM, Zhou Sheng wrote:
 
 
 
  Changes in directory llvm/lib/Transforms/Scalar:
 
  InstructionCombining.cpp updated: 1.682 - 1.683
  ---
  Log message:
 
  Make some codes more efficient.
 
  @@ -5813,7 +5816,6 @@
 case 16 : SExtType = Type::Int16Ty; break;
 case 32 : SExtType = Type::Int32Ty; break;
 case 64 : SExtType = Type::Int64Ty; break;
  -  case 128: SExtType = IntegerType::get(128); break;
 default: break;
 }
 if (SExtType) {
 
 why did you remove this?

I asked Sheng to remove it because the back ends cannot deal with 128
bit integers.

 
  @@ -5833,7 +5835,7 @@
 BinaryOperator::createShl(X, ConstantInt::get(Ty,  
  ShiftDiff));
   InsertNewInstBefore(Shift, I);
 
  -APInt Mask(APInt::getAllOnesValue(TypeBits).shl(ShiftAmt2));
  +APInt Mask(Ty-getMask().shl(ShiftAmt2));
 
 You touched many instances of this.  Please make a new  
 APInt::getHighBits method.

The method getHiBits already exists and is used to extrat the N hi bits
from an existing APInt, not construct a new value. I have just committed
a re-organization of the APInt interface (mostly for documentation
purposes) but while I was at it I added three new functions that should
address this need:

  /// Constructs an APInt value that has a contiguous range of bits set.
The
  /// bits from loBit to hiBit will be set. All other bits will be zero.
For
  /// example, with parameters(32, 15, 0) you would get 0x. If
hiBit is
  /// less than loBit then the set bits wrap. For example, with
  /// parameters (32, 3, 28), you would get 0xF00F.
  /// @param numBits the intended bit width of the result
  /// @param hiBit the index of the highest bit set.
  /// @param loBit the index of the lowest bit set.
  /// @returns An APInt value with the requested bits set.
  /// @brief Get a value with a block of bits set.
  static APInt getBitsSet(uint32_t numBits, uint32_t hiBit, uint32_t
loBit = 0);

  /// Constructs an APInt value that has the top hiBitsSet bits set.
  /// @param numBits the bitwidth of the result
  /// @param hiBitsSet the number of high-order bits set in the result.
  /// @brief Get a value with high bits set
  static APInt getHighBitsSet(uint32_t numBits, uint32_t hiBitsSet);

  /// Constructs an APInt value that has the bottom loBitsSet bits set.
  /// @param numBits the bitwidth of the result
  /// @param loBitsSet the number of low-order bits set in the result.
  /// @brief Get a value with low bits set
  static APInt getLowBitsSet(uint32_t numBits, uint32_t loBitsSet);

Reid.

 
 -Chris
 ___
 llvm-commits mailing list
 llvm-commits@cs.uiuc.edu
 http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits

___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


Re: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-03-24 Thread Chris Lattner
 Make some codes more efficient.

 @@ -5813,7 +5816,6 @@
case 16 : SExtType = Type::Int16Ty; break;
case 32 : SExtType = Type::Int32Ty; break;
case 64 : SExtType = Type::Int64Ty; break;
 -  case 128: SExtType = IntegerType::get(128); break;
default: break;
}
if (SExtType) {

 why did you remove this?

 I asked Sheng to remove it because the back ends cannot deal with 128
 bit integers.

There is partial support already in place, and at some point, it  
should be extended.  See, for example:
CodeGen/Generic/i128-arith.ll

which works on all targets with the native codegen.

 @@ -5833,7 +5835,7 @@
BinaryOperator::createShl(X, ConstantInt::get(Ty,
 ShiftDiff));
  InsertNewInstBefore(Shift, I);

 -APInt Mask(APInt::getAllOnesValue(TypeBits).shl 
 (ShiftAmt2));
 +APInt Mask(Ty-getMask().shl(ShiftAmt2));

 You touched many instances of this.  Please make a new
 APInt::getHighBits method.

 The method getHiBits already exists and is used to extrat the N hi  
 bits
 from an existing APInt, not construct a new value. I have just  
 committed
 a re-organization of the APInt interface (mostly for documentation
 purposes) but while I was at it I added three new functions that  
 should
 address this need:

Nice.

-Chris

   /// Constructs an APInt value that has a contiguous range of bits  
 set.
 The
   /// bits from loBit to hiBit will be set. All other bits will be  
 zero.
 For
   /// example, with parameters(32, 15, 0) you would get 0x. If
 hiBit is
   /// less than loBit then the set bits wrap. For example, with
   /// parameters (32, 3, 28), you would get 0xF00F.
   /// @param numBits the intended bit width of the result
   /// @param hiBit the index of the highest bit set.
   /// @param loBit the index of the lowest bit set.
   /// @returns An APInt value with the requested bits set.
   /// @brief Get a value with a block of bits set.
   static APInt getBitsSet(uint32_t numBits, uint32_t hiBit, uint32_t
 loBit = 0);

   /// Constructs an APInt value that has the top hiBitsSet bits set.
   /// @param numBits the bitwidth of the result
   /// @param hiBitsSet the number of high-order bits set in the  
 result.
   /// @brief Get a value with high bits set
   static APInt getHighBitsSet(uint32_t numBits, uint32_t hiBitsSet);

   /// Constructs an APInt value that has the bottom loBitsSet bits  
 set.
   /// @param numBits the bitwidth of the result
   /// @param loBitsSet the number of low-order bits set in the result.
   /// @brief Get a value with low bits set
   static APInt getLowBitsSet(uint32_t numBits, uint32_t loBitsSet);

 Reid.


 -Chris
 ___
 llvm-commits mailing list
 llvm-commits@cs.uiuc.edu
 http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


Re: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-03-24 Thread Chris Lattner

On Mar 22, 2007, at 1:57 PM, Reid Spencer wrote:
 @@ -7008,10 +7008,8 @@
case Instruction::ZExt: {
  // We need to emit an AND to clear the high bits.
  assert(SrcBitSize  DestBitSize  Not a zext?);
 -Constant *C =
 -  ConstantInt::get(Type::Int64Ty, (1ULL  SrcBitSize)-1);
 -if (DestBitSize  64)
 -  C = ConstantExpr::getTrunc(C, DestTy);
 +Constant *C = ConstantInt::get(APInt::getAllOnesValue 
 (SrcBitSize));
 +C = ConstantExpr::getZExt(C, DestTy);

This should be done with APInt's, not with ConstantExpr.

  return BinaryOperator::createAnd(Res, C);
}
case Instruction::SExt:
 @@ -7190,7 +7190,8 @@
  unsigned ShAmt = ShAmtV-getZExtValue();

  // Get a mask for the bits shifting in.
 -uint64_t Mask = (~0ULL  (64-ShAmt))  DestBitWidth;
 +APInt Mask(APInt::getAllOnesValue(SrcBitWidth).lshr(
 + SrcBitWidth-ShAmt).shl(DestBitWidth));

Please use the new methods.

  Value* SrcIOp0 = SrcI-getOperand(0);
  if (SrcI-hasOneUse()  MaskedValueIsZero(SrcIOp0, Mask)) {
if (ShAmt = DestBitWidth)// All zeros.
 @@ -7249,8 +7250,8 @@
// If we're actually extending zero bits and the trunc is a  
 no-op
if (MidSize  DstSize  SrcSize == DstSize) {
  // Replace both of the casts with an And of the type mask.
 -uint64_t AndValue = castIntegerType(CSrc-getType())- 
 getBitMask();
 -Constant *AndConst = ConstantInt::get(A-getType(),  
 AndValue);
 +APInt AndValue(APInt::getAllOnesValue(MidSize).zext 
 (SrcSize));
 +Constant *AndConst = ConstantInt::get(AndValue);

Likewise

-Chris

___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


Re: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

2007-03-24 Thread Chris Lattner
On Mar 23, 2007, at 11:46 AM, Reid Spencer wrote:
// shl uint X, 32 = 0 and shr ubyte Y, 9 = 0, ... just don't  
 eliminate shr
// of a signed value.
//
 -  unsigned TypeBits = Op0-getType()-getPrimitiveSizeInBits();
 -  if (Op1-getZExtValue() = TypeBits) {
 +  if (Op1-getZExtValue() = TypeBits) {  // shift amount always  
 = 32 bits

This isn't safe.  Code like:

shl i1024 %A, 123456789123456789123456789123456789

is undefined but legal.  The compiler should not crash on it.

 @@ -6462,8 +6460,8 @@
  // operation.
  //
  if (isValid  !isLeftShift  I.getOpcode() ==  
 Instruction::AShr) {
 -  uint64_t Val = Op0C-getZExtValue();
 -  isValid = ((Val  (1  (TypeBits-1))) != 0) == highBitSet;
 +  APInt Val(Op0C-getValue());
 +  isValid = ((Val  APInt::getSignBit(TypeBits)) != 0) ==  
 highBitSet;
  }

This should use operator[] to get the sign bit, or use isPositive/ 
isNegative.

  if (isValid) {
 @@ -6488,6 +6486,7 @@

if (ShiftOp  isaConstantInt(ShiftOp-getOperand(1))) {
  ConstantInt *ShiftAmt1C = castConstantInt(ShiftOp-getOperand 
 (1));
 +// shift amount always = 32 bits

Likewise, not safe.

  unsigned ShiftAmt1 = (unsigned)ShiftAmt1C-getZExtValue();
  unsigned ShiftAmt2 = (unsigned)Op1-getZExtValue();
  assert(ShiftAmt2 != 0  Should have been simplified earlier);
 @@ -6515,8 +6514,8 @@
  BinaryOperator::createAShr(X, ConstantInt::get(Ty, AmtSum));
InsertNewInstBefore(Shift, I);

 -  uint64_t Mask = Ty-getBitMask()  ShiftAmt2;
 -  return BinaryOperator::createAnd(Shift, ConstantInt::get(Ty,  
 Mask));
 +  APInt Mask(APInt::getAllOnesValue(TypeBits).lshr(ShiftAmt2));
 +  return BinaryOperator::createAnd(Shift, ConstantInt::get 
 (Mask));
  }

One of many places that need to use the new methods.

 @@ -6538,9 +6537,12 @@
// generators.
const Type *SExtType = 0;
switch (Ty-getBitWidth() - ShiftAmt1) {
 -  case 8 : SExtType = Type::Int8Ty; break;
 -  case 16: SExtType = Type::Int16Ty; break;
 -  case 32: SExtType = Type::Int32Ty; break;
 +  case 1  : SExtType = Type::Int1Ty; break;
 +  case 8  : SExtType = Type::Int8Ty; break;
 +  case 16 : SExtType = Type::Int16Ty; break;
 +  case 32 : SExtType = Type::Int32Ty; break;
 +  case 64 : SExtType = Type::Int64Ty; break;
 +  case 128: SExtType = IntegerType::get(128); break;
default: break;

It would be more efficient (code size) to do:

switch (Ty-getBitWidth() - ShiftAmt1) {
case 1:
case 8:
case 16:
case 32:
case 64:
case 128:
  SExtType = IntegerType::get(Ty-getBitWidth() - ShiftAmt1);
  break;
default: break;


 @@ -8191,7 +8193,7 @@
(ParamTy-isInteger()  ActTy-isInteger() 
 ParamTy-getPrimitiveSizeInBits() = ActTy- 
 getPrimitiveSizeInBits()) ||
(c  ParamTy-getPrimitiveSizeInBits() = ActTy- 
 getPrimitiveSizeInBits()
 -c-getSExtValue()  0);
 +c-getValue().isPositive());

Doesn't isPositive return true for zero also?  If so, this is a bug.

-Chris


___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


  1   2   3   4   >