[llvm-commits] CVS: llvm/lib/CodeGen/IntrinsicLowering.cpp

Chris Lattner lattner at cs.uiuc.edu
Wed May 11 13:02:31 PDT 2005



Changes in directory llvm/lib/CodeGen:

IntrinsicLowering.cpp updated: 1.31 -> 1.32
---
Log message:

Fix lowering of cttz to work with signed values


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

 IntrinsicLowering.cpp |    9 ++++-----
 1 files changed, 4 insertions(+), 5 deletions(-)


Index: llvm/lib/CodeGen/IntrinsicLowering.cpp
diff -u llvm/lib/CodeGen/IntrinsicLowering.cpp:1.31 llvm/lib/CodeGen/IntrinsicLowering.cpp:1.32
--- llvm/lib/CodeGen/IntrinsicLowering.cpp:1.31	Wed May 11 14:42:05 2005
+++ llvm/lib/CodeGen/IntrinsicLowering.cpp	Wed May 11 15:02:14 2005
@@ -251,13 +251,12 @@
     break;
   }
   case Intrinsic::cttz: {
+    // cttz(x) -> ctpop(~X & (X-1))
     Value *Src = CI->getOperand(1);
     Value *NotSrc = BinaryOperator::createNot(Src, Src->getName()+".not", CI);
-    Src = BinaryOperator::createAnd(NotSrc,
-                                    BinaryOperator::createSub(Src, 
-                           ConstantUInt::get(CI->getOperand(0)->getType(), 1), "", CI));
-
-    Src = LowerCTPOP(Src, CI);
+    Value *SrcM1  = ConstantInt::get(Src->getType(), 1);
+    SrcM1 = BinaryOperator::createSub(Src, SrcM1, "", CI);
+    Src = LowerCTPOP(BinaryOperator::createAnd(NotSrc, SrcM1, "", CI), CI);
     CI->replaceAllUsesWith(Src);
     break;
   }






More information about the llvm-commits mailing list