From lattner at cs.uiuc.edu Mon Aug 1 11:53:02 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Mon, 1 Aug 2005 11:53:02 -0500 Subject: [llvm-commits] CVS: llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp Message-ID: <200508011653.LAA24219@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/IPO: SimplifyLibCalls.cpp updated: 1.46 -> 1.47 --- Log message: ConstantInt::get only works for arguments < 128. SimplifyLibCalls probably has to be audited to make sure it does not make this mistake elsewhere. Also, if this code knows that the type will be unsigned, obviously one arm of this is dead. Reid, can you take a look into this further? --- Diffs of the changes: (+6 -2) SimplifyLibCalls.cpp | 8 ++++++-- 1 files changed, 6 insertions(+), 2 deletions(-) Index: llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp diff -u llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp:1.46 llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp:1.47 --- llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp:1.46 Wed Jul 27 01:12:34 2005 +++ llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp Mon Aug 1 11:52:50 2005 @@ -962,8 +962,12 @@ return false; // strlen("xyz") -> 3 (for example) - ci->replaceAllUsesWith( - ConstantInt::get(SLC.getTargetData()->getIntPtrType(),len)); + const Type *Ty = SLC.getTargetData()->getIntPtrType(); + if (Ty->isSigned()) + ci->replaceAllUsesWith(ConstantSInt::get(Ty, len)); + else + ci->replaceAllUsesWith(ConstantUInt::get(Ty, len)); + ci->eraseFromParent(); return true; } From lattner at cs.uiuc.edu Mon Aug 1 12:11:01 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Mon, 1 Aug 2005 12:11:01 -0500 Subject: [llvm-commits] CVS: llvm/test/Regression/Transforms/LoopStrengthReduce/dont_insert_redundant_ops.ll dont_reduce_bytes.ll Message-ID: <200508011711.MAA10454@zion.cs.uiuc.edu> Changes in directory llvm/test/Regression/Transforms/LoopStrengthReduce: dont_insert_redundant_ops.ll updated: 1.2 -> 1.3 dont_reduce_bytes.ll updated: 1.1 -> 1.2 --- Log message: temporarily fail these two tests until LSR evolves to support them --- Diffs of the changes: (+4 -0) dont_insert_redundant_ops.ll | 2 ++ dont_reduce_bytes.ll | 2 ++ 2 files changed, 4 insertions(+) Index: llvm/test/Regression/Transforms/LoopStrengthReduce/dont_insert_redundant_ops.ll diff -u llvm/test/Regression/Transforms/LoopStrengthReduce/dont_insert_redundant_ops.ll:1.2 llvm/test/Regression/Transforms/LoopStrengthReduce/dont_insert_redundant_ops.ll:1.3 --- llvm/test/Regression/Transforms/LoopStrengthReduce/dont_insert_redundant_ops.ll:1.2 Sun Mar 6 16:24:45 2005 +++ llvm/test/Regression/Transforms/LoopStrengthReduce/dont_insert_redundant_ops.ll Mon Aug 1 12:10:50 2005 @@ -1,6 +1,8 @@ ; Check that this test makes INDVAR and related stuff dead. ; RUN: llvm-as < %s | opt -loop-reduce | llvm-dis | grep phi | wc -l | grep 2 +; XFAIL: * + declare bool %pred() void %test1({ int, int }* %P) { Index: llvm/test/Regression/Transforms/LoopStrengthReduce/dont_reduce_bytes.ll diff -u llvm/test/Regression/Transforms/LoopStrengthReduce/dont_reduce_bytes.ll:1.1 llvm/test/Regression/Transforms/LoopStrengthReduce/dont_reduce_bytes.ll:1.2 --- llvm/test/Regression/Transforms/LoopStrengthReduce/dont_reduce_bytes.ll:1.1 Sun Mar 6 16:15:24 2005 +++ llvm/test/Regression/Transforms/LoopStrengthReduce/dont_reduce_bytes.ll Mon Aug 1 12:10:50 2005 @@ -3,6 +3,8 @@ ; RUN: llvm-as < %s | opt -loop-reduce | llvm-dis | grep 'getelementptr.*PTR.*INDVAR' +; XFAIL: * + declare bool %pred(int) void %test(sbyte* %PTR) { From alenhar2 at cs.uiuc.edu Mon Aug 1 12:35:52 2005 From: alenhar2 at cs.uiuc.edu (Andrew Lenharth) Date: Mon, 1 Aug 2005 12:35:52 -0500 Subject: [llvm-commits] CVS: llvm/lib/ExecutionEngine/JIT/JITEmitter.cpp Message-ID: <200508011735.MAA12825@zion.cs.uiuc.edu> Changes in directory llvm/lib/ExecutionEngine/JIT: JITEmitter.cpp updated: 1.75 -> 1.76 --- Log message: one cannot allocate a global, until one is done initializing the global pointers --- Diffs of the changes: (+5 -5) JITEmitter.cpp | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-) Index: llvm/lib/ExecutionEngine/JIT/JITEmitter.cpp diff -u llvm/lib/ExecutionEngine/JIT/JITEmitter.cpp:1.75 llvm/lib/ExecutionEngine/JIT/JITEmitter.cpp:1.76 --- llvm/lib/ExecutionEngine/JIT/JITEmitter.cpp:1.75 Sat Jul 30 13:33:25 2005 +++ llvm/lib/ExecutionEngine/JIT/JITEmitter.cpp Mon Aug 1 12:35:40 2005 @@ -91,17 +91,17 @@ ConstantBase = reinterpret_cast(ConstBlock.base()); GlobalBase = reinterpret_cast(GVBlock.base()); - //Allocate the GOT just like a global array - GOTBase = NULL; - if (useGOT) - GOTBase = allocateGlobal(sizeof(void*) * 8192, 8); - // Allocate stubs backwards from the base, allocate functions forward // from the base. CurStubPtr = CurFunctionPtr = FunctionBase + 512*1024;// Use 512k for stubs CurConstantPtr = ConstantBase + ConstBlock.size(); CurGlobalPtr = GlobalBase + GVBlock.size(); + + //Allocate the GOT just like a global array + GOTBase = NULL; + if (useGOT) + GOTBase = allocateGlobal(sizeof(void*) * 8192, 8); } JITMemoryManager::~JITMemoryManager() { From alenhar2 at cs.uiuc.edu Mon Aug 1 12:47:39 2005 From: alenhar2 at cs.uiuc.edu (Andrew Lenharth) Date: Mon, 1 Aug 2005 12:47:39 -0500 Subject: [llvm-commits] CVS: llvm/lib/Target/Alpha/AlphaISelPattern.cpp Message-ID: <200508011747.MAA12905@zion.cs.uiuc.edu> Changes in directory llvm/lib/Target/Alpha: AlphaISelPattern.cpp updated: 1.156 -> 1.157 --- Log message: use llabs not abs --- Diffs of the changes: (+3 -3) AlphaISelPattern.cpp | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) Index: llvm/lib/Target/Alpha/AlphaISelPattern.cpp diff -u llvm/lib/Target/Alpha/AlphaISelPattern.cpp:1.156 llvm/lib/Target/Alpha/AlphaISelPattern.cpp:1.157 --- llvm/lib/Target/Alpha/AlphaISelPattern.cpp:1.156 Thu Jul 28 13:14:47 2005 +++ llvm/lib/Target/Alpha/AlphaISelPattern.cpp Mon Aug 1 12:47:28 2005 @@ -678,7 +678,7 @@ const uint64_t two63 = 9223372036854775808ULL; // 2^63 struct ms mag; - ad = abs(d); + ad = llabs(d); t = two63 + ((uint64_t)d >> 63); anc = t - 1 - t%ad; // absolute value of nc p = 63; // initialize p @@ -1847,9 +1847,9 @@ //check if we can convert into a shift! if ((CSD = dyn_cast(N.getOperand(1).Val)) && (int64_t)CSD->getSignExtended() != 0 && - ExactLog2(abs((int64_t)CSD->getSignExtended())) != 0) + ExactLog2(llabs(CSD->getSignExtended())) != 0) { - unsigned k = ExactLog2(abs(CSD->getSignExtended())); + unsigned k = ExactLog2(llabs(CSD->getSignExtended())); Tmp1 = SelectExpr(N.getOperand(0)); if (k == 1) Tmp2 = Tmp1; From lattner at cs.uiuc.edu Mon Aug 1 13:16:48 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Mon, 1 Aug 2005 13:16:48 -0500 Subject: [llvm-commits] CVS: llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp Message-ID: <200508011816.NAA13115@zion.cs.uiuc.edu> Changes in directory llvm/lib/CodeGen/SelectionDAG: LegalizeDAG.cpp updated: 1.150 -> 1.151 --- Log message: Fix casts from long to sbyte on ppc --- Diffs of the changes: (+1 -1) LegalizeDAG.cpp | 2 +- 1 files changed, 1 insertion(+), 1 deletion(-) Index: llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp diff -u llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:1.150 llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:1.151 --- llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:1.150 Sat Jul 30 13:33:25 2005 +++ llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp Mon Aug 1 13:16:37 2005 @@ -1786,7 +1786,7 @@ case Expand: ExpandOp(Node->getOperand(0), Tmp1, Tmp2); // Truncate the low part of the expanded value to the result type - Result = DAG.getNode(ISD::TRUNCATE, VT, Tmp1); + Result = DAG.getNode(ISD::TRUNCATE, NVT, Tmp1); } break; case ISD::SIGN_EXTEND: From sabre at nondot.org Mon Aug 1 14:13:04 2005 From: sabre at nondot.org (Chris Lattner) Date: Mon, 1 Aug 2005 14:13:04 -0500 (CDT) Subject: [llvm-commits] CVS: llvm/include/llvm/System/Memory.h In-Reply-To: <1122689064.1120.2.camel@bashful.x10sys.com> References: <200507292338.SAA06170@zion.cs.uiuc.edu> <1122689064.1120.2.camel@bashful.x10sys.com> Message-ID: On Fri, 29 Jul 2005, Reid Spencer wrote: >> support near allocations for the JIT >> /// This method allocates a block of Read/Write/Execute memory that is >> /// suitable for executing dynamically generated code (e.g. JIT). An >> /// attempt to allocate \p NumBytes bytes of virtual memory is made. >> + /// \p NearBlock may point to an existing allocation in which case >> + /// an attempt is made to allocate more memory near the existing block. >> /// @throws std::string if an error occurred. >> /// @brief Allocate Read/Write/Execute memory. >> - static MemoryBlock AllocateRWX(unsigned NumBytes); >> + static MemoryBlock AllocateRWX(unsigned NumBytes, const MemoryBlock* NearBlock); > > What if one does NOT want to allocate something near another block? > Shouldn't the second argument be initialized to zero in order to retain > the existing API? A zero value would indicate that the "NearBlock" > constraint should be ignored and the function is permitted to allocate > memory anywhere available. Furthermore, this needs to be "hint" as is > done with the mmap(2) system call. The implementation already does this (treats it as a hint, and ignores the argument if it's not 0). If you want, it would be easy to make the second argument default to zero if not specified. -Chris -- http://nondot.org/sabre/ http://llvm.org/ From alenhar2 at cs.uiuc.edu Mon Aug 1 15:06:12 2005 From: alenhar2 at cs.uiuc.edu (Andrew Lenharth) Date: Mon, 1 Aug 2005 15:06:12 -0500 Subject: [llvm-commits] CVS: llvm/lib/Target/Alpha/AlphaInstrInfo.td Message-ID: <200508012006.PAA20479@zion.cs.uiuc.edu> Changes in directory llvm/lib/Target/Alpha: AlphaInstrInfo.td updated: 1.55 -> 1.56 --- Log message: update function codes to reflect /su flags that have been added since this was written --- Diffs of the changes: (+12 -12) AlphaInstrInfo.td | 24 ++++++++++++------------ 1 files changed, 12 insertions(+), 12 deletions(-) Index: llvm/lib/Target/Alpha/AlphaInstrInfo.td diff -u llvm/lib/Target/Alpha/AlphaInstrInfo.td:1.55 llvm/lib/Target/Alpha/AlphaInstrInfo.td:1.56 --- llvm/lib/Target/Alpha/AlphaInstrInfo.td:1.55 Thu Jul 28 13:14:47 2005 +++ llvm/lib/Target/Alpha/AlphaInstrInfo.td Mon Aug 1 15:06:01 2005 @@ -355,16 +355,16 @@ def CPYSN : FPForm<0x17, 0x021, "cpysn $RA,$RB,$RC">; //Copy sign negate //Basic Floating point ops -def ADDS : FPForm<0x16, 0x080, "adds/su $RA,$RB,$RC">; //Add S_floating -def ADDT : FPForm<0x16, 0x0A0, "addt/su $RA,$RB,$RC">; //Add T_floating -def SUBS : FPForm<0x16, 0x081, "subs/su $RA,$RB,$RC">; //Subtract S_floating -def SUBT : FPForm<0x16, 0x0A1, "subt/su $RA,$RB,$RC">; //Subtract T_floating -def DIVS : FPForm<0x16, 0x083, "divs/su $RA,$RB,$RC">; //Divide S_floating -def DIVT : FPForm<0x16, 0x0A3, "divt/su $RA,$RB,$RC">; //Divide T_floating -def MULS : FPForm<0x16, 0x082, "muls/su $RA,$RB,$RC">; //Multiply S_floating -def MULT : FPForm<0x16, 0x0A2, "mult/su $RA,$RB,$RC">; //Multiply T_floating -def SQRTS : FPForm<0x14, 0x08B, "sqrts $RA,$RB,$RC">; //Square root S_floating -def SQRTT : FPForm<0x14, 0x0AB, "sqrtt $RA,$RB,$RC">; //Square root T_floating +def ADDS : FPForm<0x16, 0x580, "adds/su $RA,$RB,$RC">; //Add S_floating +def ADDT : FPForm<0x16, 0x5A0, "addt/su $RA,$RB,$RC">; //Add T_floating +def SUBS : FPForm<0x16, 0x581, "subs/su $RA,$RB,$RC">; //Subtract S_floating +def SUBT : FPForm<0x16, 0x5A1, "subt/su $RA,$RB,$RC">; //Subtract T_floating +def DIVS : FPForm<0x16, 0x583, "divs/su $RA,$RB,$RC">; //Divide S_floating +def DIVT : FPForm<0x16, 0x5A3, "divt/su $RA,$RB,$RC">; //Divide T_floating +def MULS : FPForm<0x16, 0x582, "muls/su $RA,$RB,$RC">; //Multiply S_floating +def MULT : FPForm<0x16, 0x5A2, "mult/su $RA,$RB,$RC">; //Multiply T_floating +def SQRTS : FPForm<0x14, 0x58B, "sqrts/su $RA,$RB,$RC">; //Square root S_floating +def SQRTT : FPForm<0x14, 0x5AB, "sqrtt/su $RA,$RB,$RC">; //Square root T_floating //INT reg to FP reg and back again //not supported on 21164 @@ -379,8 +379,8 @@ def CVTQS : FPForm<0x16, 0x0BC, "cvtqs $RB,$RC">; //Convert quadword to S_floating def CVTQT : FPForm<0x16, 0x0BE, "cvtqt $RB,$RC">; //Convert quadword to T_floating def CVTST : FPForm<0x16, 0x2AC, "cvtsts $RB,$RC">; //Convert S_floating to T_floating -def CVTTQ : FPForm<0x16, 0x0AF, "cvttq/svc $RB,$RC">; //Convert T_floating to quadword -def CVTTS : FPForm<0x16, 0x2AC, "cvtts/su $RB,$RC">; //Convert T_floating to S_floating +def CVTTQ : FPForm<0x16, 0x52F, "cvttq/svc $RB,$RC">; //Convert T_floating to quadword +def CVTTS : FPForm<0x16, 0x5AC, "cvtts/su $RB,$RC">; //Convert T_floating to S_floating //S_floating : IEEE Single //T_floating : IEEE Double From lattner at cs.uiuc.edu Mon Aug 1 15:38:42 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Mon, 1 Aug 2005 15:38:42 -0500 Subject: [llvm-commits] CVS: llvm/include/llvm/CodeGen/MachineInstr.h Message-ID: <200508012038.PAA20728@zion.cs.uiuc.edu> Changes in directory llvm/include/llvm/CodeGen: MachineInstr.h updated: 1.162 -> 1.163 --- Log message: Mark these as V9 specific --- Diffs of the changes: (+4 -5) MachineInstr.h | 9 ++++----- 1 files changed, 4 insertions(+), 5 deletions(-) Index: llvm/include/llvm/CodeGen/MachineInstr.h diff -u llvm/include/llvm/CodeGen/MachineInstr.h:1.162 llvm/include/llvm/CodeGen/MachineInstr.h:1.163 --- llvm/include/llvm/CodeGen/MachineInstr.h:1.162 Thu Apr 21 22:45:18 2005 +++ llvm/include/llvm/CodeGen/MachineInstr.h Mon Aug 1 15:38:31 2005 @@ -503,10 +503,10 @@ void dump() const; friend std::ostream& operator<<(std::ostream& os, const MachineInstr& minstr); - // // Define iterators to access the Value operands of the Machine Instruction. // Note that these iterators only enumerate the explicit operands. - // begin() and end() are defined to produce these iterators... + // begin() and end() are defined to produce these iterators. NOTE, these are + // SparcV9 specific! // template class ValOpIterator; typedef ValOpIterator const_val_op_iterator; @@ -711,7 +711,7 @@ void SetRegForImplicitRef(unsigned i, int regNum); // - // Iterator to enumerate machine operands. + // Iterator to enumerate machine operands. NOTE, this is SPARCV9 specific! // template class ValOpIterator : public forward_iterator { @@ -763,10 +763,9 @@ } }; - // define begin() and end() + // Note: These are Sparc-V9 specific! val_op_iterator begin() { return val_op_iterator::begin(this); } val_op_iterator end() { return val_op_iterator::end(this); } - const_val_op_iterator begin() const { return const_val_op_iterator::begin(this); } From lattner at cs.uiuc.edu Mon Aug 1 19:11:03 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Mon, 1 Aug 2005 19:11:03 -0500 Subject: [llvm-commits] CVS: llvm/utils/makellvm Message-ID: <200508020011.TAA21585@zion.cs.uiuc.edu> Changes in directory llvm/utils: makellvm updated: 1.9 -> 1.10 --- Log message: make is the standard name, not gmake --- Diffs of the changes: (+1 -1) makellvm | 2 +- 1 files changed, 1 insertion(+), 1 deletion(-) Index: llvm/utils/makellvm diff -u llvm/utils/makellvm:1.9 llvm/utils/makellvm:1.10 --- llvm/utils/makellvm:1.9 Mon Sep 15 06:18:36 2003 +++ llvm/utils/makellvm Mon Aug 1 19:10:52 2005 @@ -127,7 +127,7 @@ endif cd $BUILDROOT -set CMD = "gmake $GMAKE_OPTS && (cd $LLVMDIR/tools/$EXEC && gmake $GMAKE_OPTS)" +set CMD = "make $GMAKE_OPTS && (cd $LLVMDIR/tools/$EXEC && make $GMAKE_OPTS)" if ($doit == 1) then csh -f -c "$CMD" From lattner at cs.uiuc.edu Mon Aug 1 19:12:04 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Mon, 1 Aug 2005 19:12:04 -0500 Subject: [llvm-commits] CVS: llvm/lib/Support/FileUtilities.cpp Message-ID: <200508020012.TAA21643@zion.cs.uiuc.edu> Changes in directory llvm/lib/Support: FileUtilities.cpp updated: 1.45 -> 1.46 --- Log message: 200.sixtrack prints FP numbers with a very strange notation that uses D instead of E for exponentials (e.g. 1.234D-43). Add support for this notation. --- Diffs of the changes: (+21 -3) FileUtilities.cpp | 24 +++++++++++++++++++++--- 1 files changed, 21 insertions(+), 3 deletions(-) Index: llvm/lib/Support/FileUtilities.cpp diff -u llvm/lib/Support/FileUtilities.cpp:1.45 llvm/lib/Support/FileUtilities.cpp:1.46 --- llvm/lib/Support/FileUtilities.cpp:1.45 Thu Apr 21 17:52:05 2005 +++ llvm/lib/Support/FileUtilities.cpp Mon Aug 1 19:11:53 2005 @@ -26,6 +26,8 @@ case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case '.': case '+': case '-': + case 'D': // Strange exponential notation. + case 'd': // Strange exponential notation. case 'e': case 'E': return true; default: return false; @@ -56,10 +58,26 @@ while (isspace(*F2P) && F2P != F2End) ++F2P; - // If we stop on numbers, compare their difference. + // If we stop on numbers, compare their difference. Note that some ugliness + // is built into this to permit support for numbers that use "D" or "d" as + // their exponential marker, e.g. "1.234D45". This occurs in 200.sixtrack in + // spec2k. if (isNumberChar(*F1P) && isNumberChar(*F2P)) { - V1 = strtod(F1P, &F1NumEnd); - V2 = strtod(F2P, &F2NumEnd); + bool isDNotation; + do { + isDNotation = false; + V1 = strtod(F1P, &F1NumEnd); + V2 = strtod(F2P, &F2NumEnd); + + if (*F1NumEnd == 'D' || *F1NumEnd == 'd') { + *F1NumEnd = 'e'; // Strange exponential notation! + isDNotation = true; + } + if (*F2NumEnd == 'D' || *F2NumEnd == 'd') { + *F2NumEnd = 'e'; // Strange exponential notation! + isDNotation = true; + } + } while (isDNotation); } else { // Otherwise, the diff failed. F1NumEnd = F1P; From lattner at cs.uiuc.edu Mon Aug 1 19:41:23 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Mon, 1 Aug 2005 19:41:23 -0500 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp Message-ID: <200508020041.TAA21851@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Scalar: LoopStrengthReduce.cpp updated: 1.17 -> 1.18 --- Log message: Fix an iterator invalidation problem --- Diffs of the changes: (+3 -1) LoopStrengthReduce.cpp | 4 +++- 1 files changed, 3 insertions(+), 1 deletion(-) Index: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp diff -u llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.17 llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.18 --- llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.17 Sat Jul 30 13:33:25 2005 +++ llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp Mon Aug 1 19:41:11 2005 @@ -622,7 +622,9 @@ BasicBlock::iterator I = L->getHeader()->begin(); PHINode *PN; - for (; (PN = dyn_cast(I)); ++I) { + for (; (PN = dyn_cast(I)); ) { + ++I; // Preincrement iterator to avoid invalidating it when deleting PN. + // At this point, we know that we have killed one or more GEP instructions. // It is worth checking to see if the cann indvar is also dead, so that we // can remove it as well. The requirements for the cann indvar to be From reid at x10sys.com Mon Aug 1 20:15:27 2005 From: reid at x10sys.com (Reid Spencer) Date: Mon, 01 Aug 2005 18:15:27 -0700 Subject: [llvm-commits] CVS: llvm/lib/Support/FileUtilities.cpp In-Reply-To: <200508020012.TAA21643@zion.cs.uiuc.edu> References: <200508020012.TAA21643@zion.cs.uiuc.edu> Message-ID: <42EEC92F.4030407@x10sys.com> While I don't know anything about "D", the "d" control character is used for signed decimal integers the same as %i. If you pass a float in there to sprintf and friends, you're going to get garbage at best and a crash at worst. Reid. Chris Lattner wrote: > Changes in directory llvm/lib/Support: > > FileUtilities.cpp updated: 1.45 -> 1.46 > --- > Log message: > > 200.sixtrack prints FP numbers with a very strange notation that uses D > instead of E for exponentials (e.g. 1.234D-43). Add support for this > notation. > > > > --- > Diffs of the changes: (+21 -3) > > FileUtilities.cpp | 24 +++++++++++++++++++++--- > 1 files changed, 21 insertions(+), 3 deletions(-) > > > Index: llvm/lib/Support/FileUtilities.cpp > diff -u llvm/lib/Support/FileUtilities.cpp:1.45 llvm/lib/Support/FileUtilities.cpp:1.46 > --- llvm/lib/Support/FileUtilities.cpp:1.45 Thu Apr 21 17:52:05 2005 > +++ llvm/lib/Support/FileUtilities.cpp Mon Aug 1 19:11:53 2005 > @@ -26,6 +26,8 @@ > case '0': case '1': case '2': case '3': case '4': > case '5': case '6': case '7': case '8': case '9': > case '.': case '+': case '-': > + case 'D': // Strange exponential notation. > + case 'd': // Strange exponential notation. > case 'e': > case 'E': return true; > default: return false; > @@ -56,10 +58,26 @@ > while (isspace(*F2P) && F2P != F2End) > ++F2P; > > - // If we stop on numbers, compare their difference. > + // If we stop on numbers, compare their difference. Note that some ugliness > + // is built into this to permit support for numbers that use "D" or "d" as > + // their exponential marker, e.g. "1.234D45". This occurs in 200.sixtrack in > + // spec2k. > if (isNumberChar(*F1P) && isNumberChar(*F2P)) { > - V1 = strtod(F1P, &F1NumEnd); > - V2 = strtod(F2P, &F2NumEnd); > + bool isDNotation; > + do { > + isDNotation = false; > + V1 = strtod(F1P, &F1NumEnd); > + V2 = strtod(F2P, &F2NumEnd); > + > + if (*F1NumEnd == 'D' || *F1NumEnd == 'd') { > + *F1NumEnd = 'e'; // Strange exponential notation! > + isDNotation = true; > + } > + if (*F2NumEnd == 'D' || *F2NumEnd == 'd') { > + *F2NumEnd = 'e'; // Strange exponential notation! > + isDNotation = true; > + } > + } while (isDNotation); > } else { > // Otherwise, the diff failed. > F1NumEnd = F1P; > > > > _______________________________________________ > llvm-commits mailing list > llvm-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits > From sabre at nondot.org Mon Aug 1 20:17:01 2005 From: sabre at nondot.org (Chris Lattner) Date: Mon, 1 Aug 2005 20:17:01 -0500 (CDT) Subject: [llvm-commits] CVS: llvm/lib/Support/FileUtilities.cpp In-Reply-To: <42EEC92F.4030407@x10sys.com> References: <200508020012.TAA21643@zion.cs.uiuc.edu> <42EEC92F.4030407@x10sys.com> Message-ID: On Mon, 1 Aug 2005, Reid Spencer wrote: > While I don't know anything about "D", the "d" control character is used for > signed decimal integers the same as %i. If you pass a float in there to > sprintf and friends, you're going to get garbage at best and a crash at > worst. Completely unrelated. This just allows fpcmp to parse "1.0D3" as "1.0e3", i.e. "1000". -Chris > Chris Lattner wrote: >> Changes in directory llvm/lib/Support: >> >> FileUtilities.cpp updated: 1.45 -> 1.46 >> --- >> Log message: >> >> 200.sixtrack prints FP numbers with a very strange notation that uses D >> instead of E for exponentials (e.g. 1.234D-43). Add support for this >> notation. >> >> >> >> --- >> Diffs of the changes: (+21 -3) >> >> FileUtilities.cpp | 24 +++++++++++++++++++++--- >> 1 files changed, 21 insertions(+), 3 deletions(-) >> >> >> Index: llvm/lib/Support/FileUtilities.cpp >> diff -u llvm/lib/Support/FileUtilities.cpp:1.45 >> llvm/lib/Support/FileUtilities.cpp:1.46 >> --- llvm/lib/Support/FileUtilities.cpp:1.45 Thu Apr 21 17:52:05 2005 >> +++ llvm/lib/Support/FileUtilities.cpp Mon Aug 1 19:11:53 2005 >> @@ -26,6 +26,8 @@ >> case '0': case '1': case '2': case '3': case '4': >> case '5': case '6': case '7': case '8': case '9': >> case '.': case '+': case '-': >> + case 'D': // Strange exponential notation. >> + case 'd': // Strange exponential notation. >> case 'e': >> case 'E': return true; >> default: return false; >> @@ -56,10 +58,26 @@ >> while (isspace(*F2P) && F2P != F2End) >> ++F2P; >> - // If we stop on numbers, compare their difference. >> + // If we stop on numbers, compare their difference. Note that some >> ugliness >> + // is built into this to permit support for numbers that use "D" or "d" >> as >> + // their exponential marker, e.g. "1.234D45". This occurs in >> 200.sixtrack in >> + // spec2k. >> if (isNumberChar(*F1P) && isNumberChar(*F2P)) { >> - V1 = strtod(F1P, &F1NumEnd); >> - V2 = strtod(F2P, &F2NumEnd); >> + bool isDNotation; >> + do { >> + isDNotation = false; >> + V1 = strtod(F1P, &F1NumEnd); >> + V2 = strtod(F2P, &F2NumEnd); >> + >> + if (*F1NumEnd == 'D' || *F1NumEnd == 'd') { >> + *F1NumEnd = 'e'; // Strange exponential notation! >> + isDNotation = true; >> + } >> + if (*F2NumEnd == 'D' || *F2NumEnd == 'd') { >> + *F2NumEnd = 'e'; // Strange exponential notation! >> + isDNotation = true; >> + } >> + } while (isDNotation); >> } else { >> // Otherwise, the diff failed. >> F1NumEnd = F1P; >> >> >> >> _______________________________________________ >> llvm-commits mailing list >> llvm-commits at cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits >> > > _______________________________________________ > llvm-commits mailing list > llvm-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits > -Chris -- http://nondot.org/sabre/ http://llvm.org/ From reid at x10sys.com Mon Aug 1 20:20:55 2005 From: reid at x10sys.com (Reid Spencer) Date: Mon, 01 Aug 2005 18:20:55 -0700 Subject: [llvm-commits] CVS: llvm/lib/Support/FileUtilities.cpp In-Reply-To: References: <200508020012.TAA21643@zion.cs.uiuc.edu> <42EEC92F.4030407@x10sys.com> Message-ID: <42EECA77.8010706@x10sys.com> Chris Lattner wrote: > On Mon, 1 Aug 2005, Reid Spencer wrote: > >> While I don't know anything about "D", the "d" control character is >> used for signed decimal integers the same as %i. If you pass a float >> in there to sprintf and friends, you're going to get garbage at best >> and a crash at worst. > > > Completely unrelated. This just allows fpcmp to parse "1.0D3" as > "1.0e3", i.e. "1000". Okay. I guess I should have looked at the code in a little more detail. It sure looked like sprintf stuff :) Reid. From lattner at cs.uiuc.edu Mon Aug 1 20:32:40 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Mon, 1 Aug 2005 20:32:40 -0500 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp Message-ID: <200508020132.UAA24313@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Scalar: LoopStrengthReduce.cpp updated: 1.18 -> 1.19 --- Log message: Add a comment Make LSR ignore GEP's that have loop variant base values, as we currently cannot codegen them --- Diffs of the changes: (+10 -0) LoopStrengthReduce.cpp | 10 ++++++++++ 1 files changed, 10 insertions(+) Index: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp diff -u llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.18 llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.19 --- llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.18 Mon Aug 1 19:41:11 2005 +++ llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp Mon Aug 1 20:32:29 2005 @@ -251,6 +251,9 @@ UIntPtrTy)); } else { SCEVHandle Idx = SE->getSCEV(GEP->getOperand(i)); + + // If this operand is reducible, and it's not the one we are looking at + // currently, do not process the GEP at this time. if (CanReduceSCEV(Idx, L)) return; Base = SCEVAddExpr::get(Base, GetAdjustedIndex(Idx, @@ -287,6 +290,13 @@ assert(CanReduceSCEV(GEPIndexExpr, L) && "Non reducible idx??"); + // FIXME: If the base is not loop invariant, we currently cannot emit this. + if (!Base->isLoopInvariant(L)) { + DEBUG(std::cerr << "IGNORING GEP due to non-invaiant base: " + << *Base << "\n"); + return; + } + Base = SCEVAddExpr::get(Base, cast(GEPIndexExpr)->getStart()); SCEVHandle Stride = cast(GEPIndexExpr)->getOperand(1); From lattner at cs.uiuc.edu Mon Aug 1 21:13:53 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Mon, 1 Aug 2005 21:13:53 -0500 Subject: [llvm-commits] CVS: llvm/include/llvm/System/Signals.h Message-ID: <200508020213.VAA24463@zion.cs.uiuc.edu> Changes in directory llvm/include/llvm/System: Signals.h updated: 1.14 -> 1.15 --- Log message: add a new function proto --- Diffs of the changes: (+9 -0) Signals.h | 9 +++++++++ 1 files changed, 9 insertions(+) Index: llvm/include/llvm/System/Signals.h diff -u llvm/include/llvm/System/Signals.h:1.14 llvm/include/llvm/System/Signals.h:1.15 --- llvm/include/llvm/System/Signals.h:1.14 Thu Apr 21 15:48:15 2005 +++ llvm/include/llvm/System/Signals.h Mon Aug 1 21:13:42 2005 @@ -36,6 +36,15 @@ /// @brief Print a stack trace if a fatal signal occurs. void PrintStackTraceOnErrorSignal(); + /// This function registers a function to be called when the user "interrupts" + /// the program (typically by pressing ctrl-c). When the user interrupts the + /// program, the specified interrupt function is called instead of the program + /// being killed, and the interrupt function automatically disabled. Note + /// that interrupt functions are not allowed to call any non-reentrant + /// functions. An null interrupt function pointer disables the current + /// installed function. + /// @brief Register a function to be called when ctrl-c is pressed. + void SetInterruptFunction(void (*IF)()); } // End sys namespace } // End llvm namespace From lattner at cs.uiuc.edu Mon Aug 1 21:14:34 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Mon, 1 Aug 2005 21:14:34 -0500 Subject: [llvm-commits] CVS: llvm/lib/System/Unix/Signals.inc Message-ID: <200508020214.VAA24525@zion.cs.uiuc.edu> Changes in directory llvm/lib/System/Unix: Signals.inc updated: 1.9 -> 1.10 --- Log message: Implement sys::SetInterruptFunction on Unix, stub it on win32 so that the build will not fail --- Diffs of the changes: (+18 -2) Signals.inc | 20 ++++++++++++++++++-- 1 files changed, 18 insertions(+), 2 deletions(-) Index: llvm/lib/System/Unix/Signals.inc diff -u llvm/lib/System/Unix/Signals.inc:1.9 llvm/lib/System/Unix/Signals.inc:1.10 --- llvm/lib/System/Unix/Signals.inc:1.9 Thu Jul 7 22:08:58 2005 +++ llvm/lib/System/Unix/Signals.inc Mon Aug 1 21:14:22 2005 @@ -24,6 +24,9 @@ namespace { +/// InterruptFunction - The function to call if ctrl-c is pressed. +void (*InterruptFunction)() = 0; + std::vector *FilesToRemove = 0 ; std::vector *DirectoriesToRemove = 0; @@ -116,8 +119,16 @@ DirectoriesToRemove->pop_back(); } - if (std::find(IntSigs, IntSigsEnd, Sig) != IntSigsEnd) - exit(1); // If this is an interrupt signal, exit the program + if (std::find(IntSigs, IntSigsEnd, Sig) != IntSigsEnd) { + if (InterruptFunction) { + void (*IF)() = InterruptFunction; + InterruptFunction = 0; + IF(); // run the interrupt function. + return; + } else { + exit(1); // If this is an interrupt signal, exit the program + } + } // Otherwise if it is a fault (like SEGV) output the stacktrace to // STDERR (if we can) and reissue the signal to die... @@ -134,6 +145,11 @@ namespace llvm { +void sys::SetInterruptFunction(void (*IF)()) { + InterruptFunction = IF; + RegisterHandler(SIGINT); +} + // RemoveFileOnSignal - The public API void sys::RemoveFileOnSignal(const sys::Path &Filename) { if (FilesToRemove == 0) From lattner at cs.uiuc.edu Mon Aug 1 21:14:34 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Mon, 1 Aug 2005 21:14:34 -0500 Subject: [llvm-commits] CVS: llvm/lib/System/Win32/Signals.inc Message-ID: <200508020214.VAA24529@zion.cs.uiuc.edu> Changes in directory llvm/lib/System/Win32: Signals.inc updated: 1.16 -> 1.17 --- Log message: Implement sys::SetInterruptFunction on Unix, stub it on win32 so that the build will not fail --- Diffs of the changes: (+4 -0) Signals.inc | 4 ++++ 1 files changed, 4 insertions(+) Index: llvm/lib/System/Win32/Signals.inc diff -u llvm/lib/System/Win32/Signals.inc:1.16 llvm/lib/System/Win32/Signals.inc:1.17 --- llvm/lib/System/Win32/Signals.inc:1.16 Thu Jul 7 23:50:08 2005 +++ llvm/lib/System/Win32/Signals.inc Mon Aug 1 21:14:22 2005 @@ -109,6 +109,10 @@ LeaveCriticalSection(&CriticalSection); } + +void sys::SetInterruptFunction(void (*IF)()) { + // Currently unimplemented. +} } static void Cleanup() { From lattner at cs.uiuc.edu Mon Aug 1 21:16:28 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Mon, 1 Aug 2005 21:16:28 -0500 Subject: [llvm-commits] CVS: llvm/tools/bugpoint/BugDriver.h CrashDebugger.cpp ListReducer.h Miscompilation.cpp bugpoint.cpp Message-ID: <200508020216.VAA24600@zion.cs.uiuc.edu> Changes in directory llvm/tools/bugpoint: BugDriver.h updated: 1.40 -> 1.41 CrashDebugger.cpp updated: 1.44 -> 1.45 ListReducer.h updated: 1.13 -> 1.14 Miscompilation.cpp updated: 1.69 -> 1.70 bugpoint.cpp updated: 1.24 -> 1.25 --- Log message: When the user hits ctrl-c, bugpoint should attempt to stop reduction as quickly as possible and output what it has so far. If they hit it twice, bugpoint is killed. --- Diffs of the changes: (+60 -31) BugDriver.h | 4 ++++ CrashDebugger.cpp | 43 +++++++++++++++++++++---------------------- ListReducer.h | 13 +++++++++++++ Miscompilation.cpp | 21 +++++++++++++-------- bugpoint.cpp | 10 +++++++++- 5 files changed, 60 insertions(+), 31 deletions(-) Index: llvm/tools/bugpoint/BugDriver.h diff -u llvm/tools/bugpoint/BugDriver.h:1.40 llvm/tools/bugpoint/BugDriver.h:1.41 --- llvm/tools/bugpoint/BugDriver.h:1.40 Thu Apr 21 23:13:13 2005 +++ llvm/tools/bugpoint/BugDriver.h Mon Aug 1 21:16:17 2005 @@ -35,6 +35,10 @@ extern bool DisableSimplifyCFG; +/// BugpointIsInterrupted - Set to true when the user presses ctrl-c. +/// +extern bool BugpointIsInterrupted; + class BugDriver { const std::string ToolName; // Name of bugpoint std::string ReferenceOutputFile; // Name of `good' output file Index: llvm/tools/bugpoint/CrashDebugger.cpp diff -u llvm/tools/bugpoint/CrashDebugger.cpp:1.44 llvm/tools/bugpoint/CrashDebugger.cpp:1.45 --- llvm/tools/bugpoint/CrashDebugger.cpp:1.44 Thu Jul 7 22:08:58 2005 +++ llvm/tools/bugpoint/CrashDebugger.cpp Mon Aug 1 21:16:17 2005 @@ -261,8 +261,6 @@ /// on a program, try to destructively reduce the program while still keeping /// the predicate true. static bool DebugACrash(BugDriver &BD, bool (*TestFn)(BugDriver &, Module *)) { - bool AnyReduction = false; - // See if we can get away with nuking all of the global variable initializers // in the program... if (BD.getProgram()->global_begin() != BD.getProgram()->global_end()) { @@ -282,7 +280,6 @@ std::cout << "\nChecking to see if we can delete global inits: "; if (TestFn(BD, M)) { // Still crashes? BD.setNewProgram(M); - AnyReduction = true; std::cout << "\n*** Able to remove all global initializers!\n"; } else { // No longer crashes? std::cout << " - Removing all global inits hides problem!\n"; @@ -298,17 +295,15 @@ if (!I->isExternal()) Functions.push_back(I); - if (Functions.size() > 1) { + if (Functions.size() > 1 && !BugpointIsInterrupted) { std::cout << "\n*** Attempting to reduce the number of functions " "in the testcase\n"; unsigned OldSize = Functions.size(); ReduceCrashingFunctions(BD, TestFn).reduceList(Functions); - if (Functions.size() < OldSize) { + if (Functions.size() < OldSize) BD.EmitProgressBytecode("reduced-function"); - AnyReduction = true; - } } // Attempt to delete entire basic blocks at a time to speed up @@ -316,7 +311,7 @@ // to a return instruction then running simplifycfg, which can potentially // shrinks the code dramatically quickly // - if (!DisableSimplifyCFG) { + if (!DisableSimplifyCFG && !BugpointIsInterrupted) { std::vector Blocks; for (Module::const_iterator I = BD.getProgram()->begin(), E = BD.getProgram()->end(); I != E; ++I) @@ -329,6 +324,7 @@ // larger chunks of instructions at a time! unsigned Simplification = 2; do { + if (BugpointIsInterrupted) break; --Simplification; std::cout << "\n*** Attempting to reduce testcase by deleting instruc" << "tions: Simplification Level #" << Simplification << '\n'; @@ -357,6 +353,8 @@ if (InstructionsToSkipBeforeDeleting) { --InstructionsToSkipBeforeDeleting; } else { + if (BugpointIsInterrupted) goto ExitLoops; + std::cout << "Checking instruction '" << I->getName() << "': "; Module *M = BD.deleteInstructionFromProgram(I, Simplification); @@ -365,7 +363,6 @@ // Yup, it does, we delete the old module, and continue trying // to reduce the testcase... BD.setNewProgram(M); - AnyReduction = true; InstructionsToSkipBeforeDeleting = CurInstructionNum; goto TryAgain; // I wish I had a multi-level break here! } @@ -381,22 +378,23 @@ } } while (Simplification); +ExitLoops: // Try to clean up the testcase by running funcresolve and globaldce... - std::cout << "\n*** Attempting to perform final cleanups: "; - Module *M = CloneModule(BD.getProgram()); - M = BD.performFinalCleanups(M, true); - - // Find out if the pass still crashes on the cleaned up program... - if (TestFn(BD, M)) { - BD.setNewProgram(M); // Yup, it does, keep the reduced version... - AnyReduction = true; - } else { - delete M; + if (!BugpointIsInterrupted) { + std::cout << "\n*** Attempting to perform final cleanups: "; + Module *M = CloneModule(BD.getProgram()); + M = BD.performFinalCleanups(M, true); + + // Find out if the pass still crashes on the cleaned up program... + if (TestFn(BD, M)) { + BD.setNewProgram(M); // Yup, it does, keep the reduced version... + } else { + delete M; + } } - if (AnyReduction) - BD.EmitProgressBytecode("reduced-simplified"); + BD.EmitProgressBytecode("reduced-simplified"); return false; } @@ -414,7 +412,8 @@ // Reduce the list of passes which causes the optimizer to crash... unsigned OldSize = PassesToRun.size(); - ReducePassList(*this).reduceList(PassesToRun); + if (!BugpointIsInterrupted) + ReducePassList(*this).reduceList(PassesToRun); std::cout << "\n*** Found crashing pass" << (PassesToRun.size() == 1 ? ": " : "es: ") Index: llvm/tools/bugpoint/ListReducer.h diff -u llvm/tools/bugpoint/ListReducer.h:1.13 llvm/tools/bugpoint/ListReducer.h:1.14 --- llvm/tools/bugpoint/ListReducer.h:1.13 Thu Apr 21 18:59:23 2005 +++ llvm/tools/bugpoint/ListReducer.h Mon Aug 1 21:16:17 2005 @@ -19,6 +19,8 @@ #include namespace llvm { + + extern bool BugpointIsInterrupted; template struct ListReducer { @@ -62,6 +64,12 @@ unsigned MidTop = TheList.size(); while (MidTop > 1) { + // Halt if the user presses ctrl-c. + if (BugpointIsInterrupted) { + std::cerr << "\n\n*** Reduction Interrupted, cleaning up...\n\n"; + return true; + } + unsigned Mid = MidTop / 2; std::vector Prefix(TheList.begin(), TheList.begin()+Mid); std::vector Suffix(TheList.begin()+Mid, TheList.end()); @@ -97,6 +105,11 @@ Changed = false; std::vector TrimmedList; for (unsigned i = 1; i < TheList.size()-1; ++i) { // Check interior elts + if (BugpointIsInterrupted) { + std::cerr << "\n\n*** Reduction Interrupted, cleaning up...\n\n"; + return true; + } + std::vector TestList(TheList); TestList.erase(TestList.begin()+i); Index: llvm/tools/bugpoint/Miscompilation.cpp diff -u llvm/tools/bugpoint/Miscompilation.cpp:1.69 llvm/tools/bugpoint/Miscompilation.cpp:1.70 --- llvm/tools/bugpoint/Miscompilation.cpp:1.69 Wed Jul 27 01:12:34 2005 +++ llvm/tools/bugpoint/Miscompilation.cpp Mon Aug 1 21:16:17 2005 @@ -407,6 +407,8 @@ static bool ExtractBlocks(BugDriver &BD, bool (*TestFn)(BugDriver &, Module *, Module *), std::vector &MiscompiledFunctions) { + if (BugpointIsInterrupted) return false; + std::vector Blocks; for (unsigned i = 0, e = MiscompiledFunctions.size(); i != e; ++i) for (Function::iterator I = MiscompiledFunctions[i]->begin(), @@ -493,7 +495,8 @@ MiscompiledFunctions.push_back(I); // Do the reduction... - ReduceMiscompilingFunctions(BD, TestFn).reduceList(MiscompiledFunctions); + if (!BugpointIsInterrupted) + ReduceMiscompilingFunctions(BD, TestFn).reduceList(MiscompiledFunctions); std::cout << "\n*** The following function" << (MiscompiledFunctions.size() == 1 ? " is" : "s are") @@ -513,7 +516,8 @@ DisambiguateGlobalSymbols(BD.getProgram()); // Do the reduction... - ReduceMiscompilingFunctions(BD, TestFn).reduceList(MiscompiledFunctions); + if (!BugpointIsInterrupted) + ReduceMiscompilingFunctions(BD, TestFn).reduceList(MiscompiledFunctions); std::cout << "\n*** The following function" << (MiscompiledFunctions.size() == 1 ? " is" : "s are") @@ -570,11 +574,12 @@ /// bool BugDriver::debugMiscompilation() { // Make sure something was miscompiled... - if (!ReduceMiscompilingPasses(*this).reduceList(PassesToRun)) { - std::cerr << "*** Optimized program matches reference output! No problem " - << "detected...\nbugpoint can't help you with your problem!\n"; - return false; - } + if (!BugpointIsInterrupted) + if (!ReduceMiscompilingPasses(*this).reduceList(PassesToRun)) { + std::cerr << "*** Optimized program matches reference output! No problem" + << " detected...\nbugpoint can't help you with your problem!\n"; + return false; + } std::cout << "\n*** Found miscompiling pass" << (getPassesToRun().size() == 1 ? "" : "es") << ": " @@ -663,7 +668,7 @@ for (Module::iterator F = Safe->begin(), E = Safe->end(); F != E; ++F) { if (F->isExternal() && !F->use_empty() && &*F != resolverFunc && F->getIntrinsicID() == 0 /* ignore intrinsics */) { - Function *TestFn = Test->getFunction(F->getName(), F->getFunctionType()); + Function *TestFn = Test->getNamedFunction(F->getName()); // Don't forward functions which are external in the test module too. if (TestFn && !TestFn->isExternal()) { Index: llvm/tools/bugpoint/bugpoint.cpp diff -u llvm/tools/bugpoint/bugpoint.cpp:1.24 llvm/tools/bugpoint/bugpoint.cpp:1.25 --- llvm/tools/bugpoint/bugpoint.cpp:1.24 Thu Apr 21 18:59:23 2005 +++ llvm/tools/bugpoint/bugpoint.cpp Mon Aug 1 21:16:17 2005 @@ -32,13 +32,21 @@ static cl::list PassList(cl::desc("Passes available:"), cl::ZeroOrMore); +/// BugpointIsInterrupted - Set to true when the user presses ctrl-c. +bool llvm::BugpointIsInterrupted = false; + +static void BugpointInterruptFunction() { + BugpointIsInterrupted = true; +} + int main(int argc, char **argv) { cl::ParseCommandLineOptions(argc, argv, " LLVM automatic testcase reducer. See\nhttp://" "llvm.cs.uiuc.edu/docs/CommandGuide/bugpoint.html" " for more information.\n"); sys::PrintStackTraceOnErrorSignal(); - + sys::SetInterruptFunction(BugpointInterruptFunction); + BugDriver D(argv[0]); if (D.addSources(InputFilenames)) return 1; D.addPasses(PassList.begin(), PassList.end()); From reid at x10sys.com Mon Aug 1 21:31:32 2005 From: reid at x10sys.com (Reid Spencer) Date: Mon, 01 Aug 2005 19:31:32 -0700 Subject: [llvm-commits] CVS: llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp In-Reply-To: <200508011653.LAA24219@zion.cs.uiuc.edu> References: <200508011653.LAA24219@zion.cs.uiuc.edu> Message-ID: <1122949892.6036.4.camel@bashful.x10sys.com> I audited the remaining 3 ConstantInt::get calls in SimplifyLibCalls pass. The only remaining calls all pass 0 as the second argument so they are within range of the restrictions of that call. Reid. On Mon, 2005-08-01 at 11:53 -0500, Chris Lattner wrote: > > Changes in directory llvm/lib/Transforms/IPO: > > SimplifyLibCalls.cpp updated: 1.46 -> 1.47 > --- > Log message: > > ConstantInt::get only works for arguments < 128. > > SimplifyLibCalls probably has to be audited to make sure it does not make > this mistake elsewhere. Also, if this code knows that the type will be > unsigned, obviously one arm of this is dead. > > Reid, can you take a look into this further? > > > > --- > Diffs of the changes: (+6 -2) > > SimplifyLibCalls.cpp | 8 ++++++-- > 1 files changed, 6 insertions(+), 2 deletions(-) > > > Index: llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp > diff -u llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp:1.46 llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp:1.47 > --- llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp:1.46 Wed Jul 27 01:12:34 2005 > +++ llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp Mon Aug 1 11:52:50 2005 > @@ -962,8 +962,12 @@ > return false; > > // strlen("xyz") -> 3 (for example) > - ci->replaceAllUsesWith( > - ConstantInt::get(SLC.getTargetData()->getIntPtrType(),len)); > + const Type *Ty = SLC.getTargetData()->getIntPtrType(); > + if (Ty->isSigned()) > + ci->replaceAllUsesWith(ConstantSInt::get(Ty, len)); > + else > + ci->replaceAllUsesWith(ConstantUInt::get(Ty, len)); > + > ci->eraseFromParent(); > return true; > } > > > > _______________________________________________ > llvm-commits mailing list > llvm-commits at cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part Url : http://lists.cs.uiuc.edu/pipermail/llvm-commits/attachments/20050801/2f38bf53/attachment.bin From sabre at nondot.org Mon Aug 1 21:32:24 2005 From: sabre at nondot.org (Chris Lattner) Date: Mon, 1 Aug 2005 21:32:24 -0500 (CDT) Subject: [llvm-commits] CVS: llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp In-Reply-To: <1122949892.6036.4.camel@bashful.x10sys.com> References: <200508011653.LAA24219@zion.cs.uiuc.edu> <1122949892.6036.4.camel@bashful.x10sys.com> Message-ID: On Mon, 1 Aug 2005, Reid Spencer wrote: > I audited the remaining 3 ConstantInt::get calls in SimplifyLibCalls > pass. The only remaining calls all pass 0 as the second argument so they > are within range of the restrictions of that call. Thanks a LOT Reid! -Chris > On Mon, 2005-08-01 at 11:53 -0500, Chris Lattner wrote: >> >> Changes in directory llvm/lib/Transforms/IPO: >> >> SimplifyLibCalls.cpp updated: 1.46 -> 1.47 >> --- >> Log message: >> >> ConstantInt::get only works for arguments < 128. >> >> SimplifyLibCalls probably has to be audited to make sure it does not make >> this mistake elsewhere. Also, if this code knows that the type will be >> unsigned, obviously one arm of this is dead. >> >> Reid, can you take a look into this further? >> >> >> >> --- >> Diffs of the changes: (+6 -2) >> >> SimplifyLibCalls.cpp | 8 ++++++-- >> 1 files changed, 6 insertions(+), 2 deletions(-) >> >> >> Index: llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp >> diff -u llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp:1.46 llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp:1.47 >> --- llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp:1.46 Wed Jul 27 01:12:34 2005 >> +++ llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp Mon Aug 1 11:52:50 2005 >> @@ -962,8 +962,12 @@ >> return false; >> >> // strlen("xyz") -> 3 (for example) >> - ci->replaceAllUsesWith( >> - ConstantInt::get(SLC.getTargetData()->getIntPtrType(),len)); >> + const Type *Ty = SLC.getTargetData()->getIntPtrType(); >> + if (Ty->isSigned()) >> + ci->replaceAllUsesWith(ConstantSInt::get(Ty, len)); >> + else >> + ci->replaceAllUsesWith(ConstantUInt::get(Ty, len)); >> + >> ci->eraseFromParent(); >> return true; >> } >> >> >> >> _______________________________________________ >> llvm-commits mailing list >> llvm-commits at cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits > -Chris -- http://nondot.org/sabre/ http://llvm.org/ From lattner at cs.uiuc.edu Mon Aug 1 21:44:42 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Mon, 1 Aug 2005 21:44:42 -0500 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp Message-ID: <200508020244.VAA26339@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Scalar: LoopStrengthReduce.cpp updated: 1.19 -> 1.20 --- Log message: Simplify for loop, clear a per-loop map after processing each loop --- Diffs of the changes: (+2 -1) LoopStrengthReduce.cpp | 3 ++- 1 files changed, 2 insertions(+), 1 deletion(-) Index: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp diff -u llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.19 llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.20 --- llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.19 Mon Aug 1 20:32:29 2005 +++ llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp Mon Aug 1 21:44:31 2005 @@ -632,7 +632,7 @@ BasicBlock::iterator I = L->getHeader()->begin(); PHINode *PN; - for (; (PN = dyn_cast(I)); ) { + while ((PN = dyn_cast(I))) { ++I; // Preincrement iterator to avoid invalidating it when deleting PN. // At this point, we know that we have killed one or more GEP instructions. @@ -664,5 +664,6 @@ } IVUsesByStride.clear(); + CastedBasePointers.clear(); return; } From lattner at cs.uiuc.edu Mon Aug 1 21:52:13 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Mon, 1 Aug 2005 21:52:13 -0500 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp Message-ID: <200508020252.VAA26426@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Scalar: LoopStrengthReduce.cpp updated: 1.20 -> 1.21 --- Log message: add a comment, make a check more lenient --- Diffs of the changes: (+10 -8) LoopStrengthReduce.cpp | 18 ++++++++++-------- 1 files changed, 10 insertions(+), 8 deletions(-) Index: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp diff -u llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.20 llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.21 --- llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.20 Mon Aug 1 21:44:31 2005 +++ llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp Mon Aug 1 21:52:02 2005 @@ -71,6 +71,9 @@ const TargetData *TD; const Type *UIntPtrTy; bool Changed; + + /// MaxTargetAMSize - This is the maximum power-of-two scale value that the + /// target can handle for free with its addressing modes. unsigned MaxTargetAMSize; /// IVUsesByStride - Keep track of all uses of induction variables that we @@ -649,15 +652,14 @@ // compared against some value to decide loop termination. if (PN->hasOneUse()) { BinaryOperator *BO = dyn_cast(*(PN->use_begin())); - if (BO && BO->getOpcode() == Instruction::Add) - if (BO->hasOneUse()) { - if (PN == dyn_cast(*(BO->use_begin()))) { - DeadInsts.insert(BO); - // Break the cycle, then delete the PHI. - PN->replaceAllUsesWith(UndefValue::get(PN->getType())); - PN->eraseFromParent(); - } + if (BO && BO->hasOneUse()) { + if (PN == *(BO->use_begin())) { + DeadInsts.insert(BO); + // Break the cycle, then delete the PHI. + PN->replaceAllUsesWith(UndefValue::get(PN->getType())); + PN->eraseFromParent(); } + } } } DeleteTriviallyDeadInstructions(DeadInsts); From jeffc at jolt-lang.org Mon Aug 1 22:04:59 2005 From: jeffc at jolt-lang.org (Jeff Cohen) Date: Mon, 1 Aug 2005 22:04:59 -0500 Subject: [llvm-commits] CVS: llvm/lib/System/Win32/Signals.inc Message-ID: <200508020304.WAA27457@zion.cs.uiuc.edu> Changes in directory llvm/lib/System/Win32: Signals.inc updated: 1.17 -> 1.18 --- Log message: Implement SetInterruptFunction for Windows. --- Diffs of the changes: (+25 -1) Signals.inc | 26 +++++++++++++++++++++++++- 1 files changed, 25 insertions(+), 1 deletion(-) Index: llvm/lib/System/Win32/Signals.inc diff -u llvm/lib/System/Win32/Signals.inc:1.17 llvm/lib/System/Win32/Signals.inc:1.18 --- llvm/lib/System/Win32/Signals.inc:1.17 Mon Aug 1 21:14:22 2005 +++ llvm/lib/System/Win32/Signals.inc Mon Aug 1 22:04:47 2005 @@ -29,6 +29,9 @@ static LONG WINAPI LLVMUnhandledExceptionFilter(LPEXCEPTION_POINTERS ep); static BOOL WINAPI LLVMConsoleCtrlHandler(DWORD dwCtrlType); +// InterruptFunction - The function to call if ctrl-c is pressed. +static void (*InterruptFunction)() = 0; + static std::vector *FilesToRemove = NULL; static std::vector *DirectoriesToRemove = NULL; static bool RegisteredUnhandledExceptionFilter = false; @@ -111,7 +114,9 @@ void sys::SetInterruptFunction(void (*IF)()) { - // Currently unimplemented. + InterruptFunction = IF; + RegisterHandler(); + LeaveCriticalSection(&CriticalSection); } } @@ -234,9 +239,28 @@ } static BOOL WINAPI LLVMConsoleCtrlHandler(DWORD dwCtrlType) { + EnterCriticalSection(&CriticalSection); Cleanup(); + // If an interrupt function has been set, go and run one it; otherwise, + // the process dies. + void (*IF)() = InterruptFunction; + InterruptFunction = 0; // Don't run it on another CTRL-C. + + if (IF) { + try { + IF(); // Run it now. + } catch (...) { + // Kill the process on an exception. + LeaveCriticalSection(&CriticalSection); + return FALSE; + } + LeaveCriticalSection(&CriticalSection); + return TRUE; // Don't kill the process. + } + // Allow normal processing to take place; i.e., the process dies. + LeaveCriticalSection(&CriticalSection); return FALSE; } From jeffc at jolt-lang.org Mon Aug 1 22:04:59 2005 From: jeffc at jolt-lang.org (Jeff Cohen) Date: Mon, 1 Aug 2005 22:04:59 -0500 Subject: [llvm-commits] CVS: llvm/include/llvm/System/Signals.h Message-ID: <200508020304.WAA27463@zion.cs.uiuc.edu> Changes in directory llvm/include/llvm/System: Signals.h updated: 1.15 -> 1.16 --- Log message: Implement SetInterruptFunction for Windows. --- Diffs of the changes: (+2 -1) Signals.h | 3 ++- 1 files changed, 2 insertions(+), 1 deletion(-) Index: llvm/include/llvm/System/Signals.h diff -u llvm/include/llvm/System/Signals.h:1.15 llvm/include/llvm/System/Signals.h:1.16 --- llvm/include/llvm/System/Signals.h:1.15 Mon Aug 1 21:13:42 2005 +++ llvm/include/llvm/System/Signals.h Mon Aug 1 22:04:47 2005 @@ -42,7 +42,8 @@ /// being killed, and the interrupt function automatically disabled. Note /// that interrupt functions are not allowed to call any non-reentrant /// functions. An null interrupt function pointer disables the current - /// installed function. + /// installed function. Note also that the handler may be executed on a + /// different thread on some platforms. /// @brief Register a function to be called when ctrl-c is pressed. void SetInterruptFunction(void (*IF)()); } // End sys namespace From lattner at cs.uiuc.edu Mon Aug 1 22:23:14 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Mon, 1 Aug 2005 22:23:14 -0500 Subject: [llvm-commits] CVS: llvm/test/Regression/Transforms/SimplifyCFG/2005-08-01-PHIUpdateFail.ll Message-ID: <200508020323.WAA31328@zion.cs.uiuc.edu> Changes in directory llvm/test/Regression/Transforms/SimplifyCFG: 2005-08-01-PHIUpdateFail.ll added (r1.1) --- Log message: New testcase that caused simplifycfg to crash --- Diffs of the changes: (+96 -0) 2005-08-01-PHIUpdateFail.ll | 96 ++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 96 insertions(+) Index: llvm/test/Regression/Transforms/SimplifyCFG/2005-08-01-PHIUpdateFail.ll diff -c /dev/null llvm/test/Regression/Transforms/SimplifyCFG/2005-08-01-PHIUpdateFail.ll:1.1 *** /dev/null Mon Aug 1 22:23:13 2005 --- llvm/test/Regression/Transforms/SimplifyCFG/2005-08-01-PHIUpdateFail.ll Mon Aug 1 22:23:03 2005 *************** *** 0 **** --- 1,96 ---- + ; RUN: llvm-as < %s | opt -simplifycfg -disable-output + + void %main() { + entry: + %tmp.14.i19 = seteq int 0, 2 ; [#uses=1] + br bool %tmp.14.i19, label %endif.1.i20, label %read_min.exit + + endif.1.i20: ; preds = %entry + %tmp.9.i.i = seteq sbyte* null, null ; [#uses=1] + br bool %tmp.9.i.i, label %then.i12.i, label %then.i.i + + then.i.i: ; preds = %endif.1.i20 + ret void + + then.i12.i: ; preds = %endif.1.i20 + %tmp.9.i4.i = seteq sbyte* null, null ; [#uses=1] + br bool %tmp.9.i4.i, label %endif.2.i33, label %then.i5.i + + then.i5.i: ; preds = %then.i12.i + ret void + + endif.2.i33: ; preds = %then.i12.i + br bool false, label %loopexit.0.i40, label %no_exit.0.i35 + + no_exit.0.i35: ; preds = %no_exit.0.i35, %endif.2.i33 + %tmp.130.i = setlt int 0, 0 ; [#uses=1] + br bool %tmp.130.i, label %loopexit.0.i40.loopexit, label %no_exit.0.i35 + + loopexit.0.i40.loopexit: ; preds = %no_exit.0.i35 + br label %loopexit.0.i40 + + loopexit.0.i40: ; preds = %loopexit.0.i40.loopexit, %endif.2.i33 + %tmp.341.i = seteq int 0, 0 ; [#uses=1] + br bool %tmp.341.i, label %loopentry.1.i, label %read_min.exit + + loopentry.1.i: ; preds = %loopexit.0.i40 + %tmp.347.i = setgt int 0, 0 ; [#uses=1] + br bool %tmp.347.i, label %no_exit.1.i41, label %loopexit.2.i44 + + no_exit.1.i41: ; preds = %endif.5.i, %loopentry.1.i + %indvar.i42 = phi uint [ %indvar.next.i, %endif.5.i ], [ 0, %loopentry.1.i ] ; [#uses=1] + %tmp.355.i = seteq int 0, 3 ; [#uses=1] + br bool %tmp.355.i, label %endif.5.i, label %read_min.exit + + endif.5.i: ; preds = %no_exit.1.i41 + %tmp.34773.i = setgt int 0, 0 ; [#uses=1] + %indvar.next.i = add uint %indvar.i42, 1 ; [#uses=1] + br bool %tmp.34773.i, label %no_exit.1.i41, label %loopexit.1.i.loopexit + + loopexit.1.i.loopexit: ; preds = %endif.5.i + ret void + + loopexit.2.i44: ; preds = %loopentry.1.i + ret void + + read_min.exit: ; preds = %no_exit.1.i41, %loopexit.0.i40, %entry + %tmp.23 = seteq int 0, 0 ; [#uses=1] + br bool %tmp.23, label %endif.1, label %then.1 + + then.1: ; preds = %read_min.exit + br bool false, label %endif.0.i, label %then.0.i + + then.0.i: ; preds = %then.1 + br bool false, label %endif.1.i, label %then.1.i + + endif.0.i: ; preds = %then.1 + br bool false, label %endif.1.i, label %then.1.i + + then.1.i: ; preds = %endif.0.i, %then.0.i + br bool false, label %getfree.exit, label %then.2.i + + endif.1.i: ; preds = %endif.0.i, %then.0.i + br bool false, label %getfree.exit, label %then.2.i + + then.2.i: ; preds = %endif.1.i, %then.1.i + ret void + + getfree.exit: ; preds = %endif.1.i, %then.1.i + ret void + + endif.1: ; preds = %read_min.exit + %tmp.27.i = getelementptr int* null, int 0 + br bool false, label %loopexit.0.i15, label %no_exit.0.i14 + + no_exit.0.i14: ; preds = %endif.1 + ret void + + loopexit.0.i15: ; preds = %endif.1 + br bool false, label %primal_start_artificial.exit, label %no_exit.1.i16 + + no_exit.1.i16: ; preds = %no_exit.1.i16, %loopexit.0.i15 + br bool false, label %primal_start_artificial.exit, label %no_exit.1.i16 + + primal_start_artificial.exit: ; preds = %no_exit.1.i16, %loopexit.0.i15 + ret void + } From lattner at cs.uiuc.edu Mon Aug 1 22:24:16 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Mon, 1 Aug 2005 22:24:16 -0500 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Utils/SimplifyCFG.cpp Message-ID: <200508020324.WAA31407@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Utils: SimplifyCFG.cpp updated: 1.72 -> 1.73 --- Log message: This code was very close, but not quite right. It did not take into consideration the case where a reference in an unreachable block could occur. This fixes Transforms/SimplifyCFG/2005-08-01-PHIUpdateFail.ll, something I ran into while bugpoint'ing another pass. --- Diffs of the changes: (+10 -3) SimplifyCFG.cpp | 13 ++++++++++--- 1 files changed, 10 insertions(+), 3 deletions(-) Index: llvm/lib/Transforms/Utils/SimplifyCFG.cpp diff -u llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.72 llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.73 --- llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.72 Thu Jun 16 20:45:53 2005 +++ llvm/lib/Transforms/Utils/SimplifyCFG.cpp Mon Aug 1 22:24:05 2005 @@ -894,9 +894,16 @@ // Move all PHI nodes in BB to Succ if they are alive, otherwise // delete them. while (PHINode *PN = dyn_cast(&BB->front())) - if (PN->use_empty()) - BB->getInstList().erase(BB->begin()); // Nuke instruction. - else { + if (PN->use_empty() || Succ->getSinglePredecessor() == 0) { + // We can only move the PHI node into Succ if BB dominates Succ. + // Since BB only has a single successor (Succ), the PHI nodes + // will dominate Succ, unless Succ has multiple predecessors. In + // this case, the PHIs are either dead, or have references in dead + // blocks. In either case, we can just remove them. + if (!PN->use_empty()) // Uses in dead block? + PN->replaceAllUsesWith(UndefValue::get(PN->getType())); + PN->eraseFromParent(); // Nuke instruction. + } else { // The instruction is alive, so this means that Succ must have // *ONLY* had BB as a predecessor, and the PHI node is still valid // now. Simply move it into Succ, because we know that BB From jeffc at jolt-lang.org Mon Aug 1 22:26:43 2005 From: jeffc at jolt-lang.org (Jeff Cohen) Date: Mon, 1 Aug 2005 22:26:43 -0500 Subject: [llvm-commits] CVS: llvm/lib/System/Win32/Signals.inc Message-ID: <200508020326.WAA31441@zion.cs.uiuc.edu> Changes in directory llvm/lib/System/Win32: Signals.inc updated: 1.18 -> 1.19 --- Log message: It's dangerous coding on Mondays. --- Diffs of the changes: (+5 -8) Signals.inc | 13 +++++-------- 1 files changed, 5 insertions(+), 8 deletions(-) Index: llvm/lib/System/Win32/Signals.inc diff -u llvm/lib/System/Win32/Signals.inc:1.18 llvm/lib/System/Win32/Signals.inc:1.19 --- llvm/lib/System/Win32/Signals.inc:1.18 Mon Aug 1 22:04:47 2005 +++ llvm/lib/System/Win32/Signals.inc Mon Aug 1 22:26:32 2005 @@ -114,8 +114,8 @@ void sys::SetInterruptFunction(void (*IF)()) { - InterruptFunction = IF; RegisterHandler(); + InterruptFunction = IF; LeaveCriticalSection(&CriticalSection); } } @@ -239,6 +239,7 @@ } static BOOL WINAPI LLVMConsoleCtrlHandler(DWORD dwCtrlType) { + // We are running in our very own thread, courtesy of Windows. EnterCriticalSection(&CriticalSection); Cleanup(); @@ -248,13 +249,9 @@ InterruptFunction = 0; // Don't run it on another CTRL-C. if (IF) { - try { - IF(); // Run it now. - } catch (...) { - // Kill the process on an exception. - LeaveCriticalSection(&CriticalSection); - return FALSE; - } + // Note: if the interrupt function throws an exception, there is nothing + // to catch it in this thread so it will kill the process. + IF(); // Run it now. LeaveCriticalSection(&CriticalSection); return TRUE; // Don't kill the process. } From lattner at cs.uiuc.edu Mon Aug 1 22:31:25 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Mon, 1 Aug 2005 22:31:25 -0500 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp Message-ID: <200508020331.WAA31789@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Scalar: LoopStrengthReduce.cpp updated: 1.21 -> 1.22 --- Log message: Like the comment says, do not insert cast instructions before phi nodes --- Diffs of the changes: (+4 -0) LoopStrengthReduce.cpp | 4 ++++ 1 files changed, 4 insertions(+) Index: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp diff -u llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.21 llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.22 --- llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.21 Mon Aug 1 21:52:02 2005 +++ llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp Mon Aug 1 22:31:14 2005 @@ -232,6 +232,10 @@ else ++InsertPt; } + + // Do not insert casts into the middle of PHI node blocks. + while (isa(InsertPt)) ++InsertPt; + BP = new CastInst(GEP->getOperand(0), UIntPtrTy, GEP->getOperand(0)->getName(), InsertPt); } From brukman at cs.uiuc.edu Tue Aug 2 11:05:11 2005 From: brukman at cs.uiuc.edu (Misha Brukman) Date: Tue, 2 Aug 2005 11:05:11 -0500 Subject: [llvm-commits] CVS: llvm/lib/System/Mutex.cpp Message-ID: <200508021605.LAA01733@zion.cs.uiuc.edu> Changes in directory llvm/lib/System: Mutex.cpp updated: 1.4 -> 1.5 --- Log message: Fix grammar: it's == "it is". --- Diffs of the changes: (+1 -1) Mutex.cpp | 2 +- 1 files changed, 1 insertion(+), 1 deletion(-) Index: llvm/lib/System/Mutex.cpp diff -u llvm/lib/System/Mutex.cpp:1.4 llvm/lib/System/Mutex.cpp:1.5 --- llvm/lib/System/Mutex.cpp:1.4 Wed Jul 27 01:12:33 2005 +++ llvm/lib/System/Mutex.cpp Tue Aug 2 11:04:59 2005 @@ -38,7 +38,7 @@ // Note: all LLVM tools will link against -lpthread if its available since it // is configured into the LIBS variable. // Note: this line of code generates a warning if pthread_mutex_init is not -// declared with weak linkage. Its safe to ignore the warning. +// declared with weak linkage. It's safe to ignore the warning. static const bool pthread_enabled = static_cast(pthread_mutex_init); // Construct a Mutex using pthread calls From lattner at cs.uiuc.edu Tue Aug 2 14:08:00 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue, 2 Aug 2005 14:08:00 -0500 Subject: [llvm-commits] CVS: llvm/lib/Target/PowerPC/PPC32ISelPattern.cpp Message-ID: <200508021908.OAA06946@zion.cs.uiuc.edu> Changes in directory llvm/lib/Target/PowerPC: PPC32ISelPattern.cpp updated: 1.109 -> 1.110 --- Log message: add a pass name to make debugging dumps nicer --- Diffs of the changes: (+4 -0) PPC32ISelPattern.cpp | 4 ++++ 1 files changed, 4 insertions(+) Index: llvm/lib/Target/PowerPC/PPC32ISelPattern.cpp diff -u llvm/lib/Target/PowerPC/PPC32ISelPattern.cpp:1.109 llvm/lib/Target/PowerPC/PPC32ISelPattern.cpp:1.110 --- llvm/lib/Target/PowerPC/PPC32ISelPattern.cpp:1.109 Thu Jul 28 00:23:43 2005 +++ llvm/lib/Target/PowerPC/PPC32ISelPattern.cpp Tue Aug 2 14:07:49 2005 @@ -571,6 +571,10 @@ unsigned SelectAddr(SDOperand N, unsigned& Reg, int& offset); void SelectBranchCC(SDOperand N); + + virtual const char *getPassName() const { + return "PowerPC Pattern Instruction Selection"; + } }; /// ExactLog2 - This function solves for (Val == 1 << (N-1)) and returns N. It From lattner at cs.uiuc.edu Tue Aug 2 14:09:55 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue, 2 Aug 2005 14:09:55 -0500 Subject: [llvm-commits] CVS: llvm-test/External/SPEC/CINT2000/252.eon/Makefile Message-ID: <200508021909.OAA07099@zion.cs.uiuc.edu> Changes in directory llvm-test/External/SPEC/CINT2000/252.eon: Makefile updated: 1.11 -> 1.12 --- Log message: add darwin compatibility --- Diffs of the changes: (+7 -0) Makefile | 7 +++++++ 1 files changed, 7 insertions(+) Index: llvm-test/External/SPEC/CINT2000/252.eon/Makefile diff -u llvm-test/External/SPEC/CINT2000/252.eon/Makefile:1.11 llvm-test/External/SPEC/CINT2000/252.eon/Makefile:1.12 --- llvm-test/External/SPEC/CINT2000/252.eon/Makefile:1.11 Sun Nov 14 02:20:47 2004 +++ llvm-test/External/SPEC/CINT2000/252.eon/Makefile Tue Aug 2 14:09:44 2005 @@ -7,6 +7,13 @@ # Yes, we know this is an old crufty C++ benchmark. Don't tell us about it GCC! CPPFLAGS = -include errno.h -Wno-deprecated -Wno-non-template-friend -DHAS_ERRLIST -DUSE_STRERROR -DSPEC_STDCPP -DNDEBUG +include $(LEVEL)/Makefile.config + +ifeq ($(ARCH),PowerPC) + CPPFLAGS += -DFMAX_IS_DOUBLE +endif + + Source = $(addprefix $(SPEC_BENCH_DIR)/src/, \ ggCoverageSolidTexture.cc ggPathDielectricMaterial.cc ggBox2.cc \ ggBox3.cc ggRasterSurfaceTexture.cc ggJitterSample1.cc \ From lattner at cs.uiuc.edu Tue Aug 2 14:14:36 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue, 2 Aug 2005 14:14:36 -0500 Subject: [llvm-commits] CVS: llvm/docs/HistoricalNotes/2003-01-23-CygwinNotes.txt Message-ID: <200508021914.OAA07291@zion.cs.uiuc.edu> Changes in directory llvm/docs/HistoricalNotes: 2003-01-23-CygwinNotes.txt updated: 1.1 -> 1.2 --- Log message: Update a doc, patch contributed by Jim Laskey! --- Diffs of the changes: (+3 -6) 2003-01-23-CygwinNotes.txt | 9 +++------ 1 files changed, 3 insertions(+), 6 deletions(-) Index: llvm/docs/HistoricalNotes/2003-01-23-CygwinNotes.txt diff -u llvm/docs/HistoricalNotes/2003-01-23-CygwinNotes.txt:1.1 llvm/docs/HistoricalNotes/2003-01-23-CygwinNotes.txt:1.2 --- llvm/docs/HistoricalNotes/2003-01-23-CygwinNotes.txt:1.1 Thu Jan 23 15:17:02 2003 +++ llvm/docs/HistoricalNotes/2003-01-23-CygwinNotes.txt Tue Aug 2 14:14:25 2005 @@ -17,15 +17,12 @@ DONT_BUILD_RELINKED. This breaks all the tools makefiles; you just need to change them to have .a's. -5. Cygwin's math.h defines log2(); it needs to be #undefed if already defined - in MathExtras.h. +5. There isn't a . -6. There isn't a . - -7. There isn't a mallinfo() (or, at least, it's documented, but it doesn't seem +6. There isn't a mallinfo() (or, at least, it's documented, but it doesn't seem to link). -8. The version of Bison that cygwin (and newer Linux versions) comes with +7. The version of Bison that cygwin (and newer Linux versions) comes with does not like = signs in rules. Burg's gram.yc source file uses them. I think you can just take them out. From lattner at cs.uiuc.edu Tue Aug 2 14:15:41 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue, 2 Aug 2005 14:15:41 -0500 Subject: [llvm-commits] CVS: llvm/include/llvm/Support/MathExtras.h Message-ID: <200508021915.OAA07355@zion.cs.uiuc.edu> Changes in directory llvm/include/llvm/Support: MathExtras.h updated: 1.16 -> 1.17 --- Log message: Consolidate all of the various log2 computing functions into MathExtras.h. Also, provide accelerated implementations when building with GCC. Patch contributed by Jim Laskey! --- Diffs of the changes: (+135 -22) MathExtras.h | 157 ++++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 135 insertions(+), 22 deletions(-) Index: llvm/include/llvm/Support/MathExtras.h diff -u llvm/include/llvm/Support/MathExtras.h:1.16 llvm/include/llvm/Support/MathExtras.h:1.17 --- llvm/include/llvm/Support/MathExtras.h:1.16 Thu Apr 21 15:44:59 2005 +++ llvm/include/llvm/Support/MathExtras.h Tue Aug 2 14:15:30 2005 @@ -18,32 +18,145 @@ namespace llvm { -#if defined(log2) -# undef log2 +// NOTE: The following support functions use the _32/_64 extensions instead of type +// overloading so that signed and unsigned integers can be used without ambiguity. + + +// Hi_32 - This function returns the high 32 bits of a 64 bit value. +inline unsigned Hi_32(uint64_t Value) { + return (unsigned)(Value >> 32); +} + +// Lo_32 - This function returns the low 32 bits of a 64 bit value. +inline unsigned Lo_32(uint64_t Value) { + return (unsigned)Value; +} + +// is?Type - these functions produce optimal testing for integer data types. +inline bool isInt8 (int Value) { return ( signed char )Value == Value; } +inline bool isUInt8 (int Value) { return (unsigned char )Value == Value; } +inline bool isInt16 (int Value) { return ( signed short)Value == Value; } +inline bool isUInt16(int Value) { return (unsigned short)Value == Value; } +inline bool isInt32 (int64_t Value) { return ( signed int )Value == Value; } +inline bool isUInt32(int64_t Value) { return (unsigned int )Value == Value; } + +// isMask_32 - This function returns true if the argument is a sequence of ones starting +// at the least significant bit with the remainder zero (32 bit version.) +// Ex. isMask_32(0x0000FFFFU) == true. +inline const bool isMask_32(unsigned Value) { + return Value && ((Value + 1) & Value) == 0; +} + +// isMask_64 - This function returns true if the argument is a sequence of ones starting +// at the least significant bit with the remainder zero (64 bit version.) +inline const bool isMask_64(uint64_t Value) { + return Value && ((Value + 1) & Value) == 0; +} + +// isShiftedMask_32 - This function returns true if the argument contains a sequence of ones +// with the remainder zero (32 bit version.) +// Ex. isShiftedMask_32(0x0000FF00U) == true. +inline const bool isShiftedMask_32(unsigned Value) { + return isMask_32((Value - 1) | Value); +} + +// isShiftedMask_64 - This function returns true if the argument contains a sequence of ones +// with the remainder zero (64 bit version.) +inline const bool isShiftedMask_64(uint64_t Value) { + return isMask_64((Value - 1) | Value); +} + +// isPowerOf2_32 - This function returns true if the argument is a power of two > 0. +// Ex. isPowerOf2_32(0x00100000U) == true (32 bit edition.) +inline bool isPowerOf2_32(unsigned Value) { + return Value && !(Value & (Value - 1)); +} + +// isPowerOf2_64 - This function returns true if the argument is a power of two > 0 +// (64 bit edition.) +inline bool isPowerOf2_64(uint64_t Value) { + return Value && !(Value & (Value - 1LL)); +} + +// CountLeadingZeros_32 - this function performs the platform optimal form +// of counting the number of zeros from the most significant bit to the first one bit. +// Ex. CountLeadingZeros_32(0x00F000FF) == 8. +// Returns 32 if the word is zero. +inline unsigned CountLeadingZeros_32(unsigned Value) { + unsigned Count; // result + #if __GNUC__ >= 4 + // PowerPC is defined for __builtin_clz(0) + #if defined(__ppc__) || defined(__ppc64__) + if (!Value) return 32; #endif + Count = __builtin_clz(Value); + #else + if (!Value) return 32; + Count = 0; + // bisecton method for count leading zeros + for (unsigned Shift = 32 >> 1; Shift; Shift >>= 1) { + unsigned Tmp = Value >> Shift; + if (Tmp) { + Count |= Shift; + Value = Tmp; + } + } + #endif + return Count; +} + +// CountLeadingZeros_64 - This function performs the platform optimal form +// of counting the number of zeros from the most significant bit to the first one bit +// (64 bit edition.) +// Returns 64 if the word is zero. +inline unsigned CountLeadingZeros_64(uint64_t Value) { + unsigned Count; // result + #if __GNUC__ >= 4 + // PowerPC is defined for __builtin_clzll(0) + #if defined(__ppc__) || defined(__ppc64__) + if (!Value) return 64; + #endif + Count = __builtin_clzll(Value); + #elif sizeof(long) == sizeof(int64_t) + if (!Value) return 64; + Count = 0; + // bisecton method for count leading zeros + for (uint64_t Shift = 64 >> 1; Shift; Shift >>= 1) { + uint64_t Tmp = Value >> Shift; + if (Tmp) { + Count |= Shift; + Value = Tmp; + } +} + #else + // get hi portion + unsigned Hi = Hi_32(Value); + + // if some bits in hi portion + if (Hi) { + // leading zeros in hi portion plus all bits in lo portion + Count = CountLeadingZeros_32(Hi) + 32; + } else { + // get lo portion + unsigned Lo = Lo_32(Value); + // same as 32 bit value + Count = CountLeadingZeros_32(Lo); + } + #endif + return Count; +} -inline unsigned log2(uint64_t C) { - unsigned getPow; - for (getPow = 0; C > 1; ++getPow) - C >>= 1; - return getPow; -} - -inline unsigned log2(unsigned C) { - unsigned getPow; - for (getPow = 0; C > 1; ++getPow) - C >>= 1; - return getPow; -} - -inline bool isPowerOf2(int64_t C, unsigned &getPow) { - if (C < 0) C = -C; - if (C > 0 && C == (C & ~(C - 1))) { - getPow = log2(static_cast(C)); - return true; +// Log2_32 - This function returns the floor log base 2 of the specified value, -1 if the value is zero. +// (32 bit edition.) +// Ex. Log2_32(32) == 5, Log2_32(1) == 0, Log2_32(0) == -1 +inline unsigned Log2_32(unsigned Value) { + return 31 - CountLeadingZeros_32(Value); } - return false; +// Log2_64 - This function returns the floor log base 2 of the specified value, -1 if the value is zero. +// (64 bit edition.) +inline unsigned Log2_64(unsigned Value) { + return 63 - CountLeadingZeros_64(Value); } // Platform-independent wrappers for the C99 isnan() function. From lattner at cs.uiuc.edu Tue Aug 2 14:17:09 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue, 2 Aug 2005 14:17:09 -0500 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp Message-ID: <200508021917.OAA07425@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Scalar: InstructionCombining.cpp updated: 1.360 -> 1.361 --- Log message: Update to use the new MathExtras.h support for log2 computation. Patch contributed by Jim Laskey! --- Diffs of the changes: (+15 -22) InstructionCombining.cpp | 37 +++++++++++++++---------------------- 1 files changed, 15 insertions(+), 22 deletions(-) Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.360 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.361 --- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.360 Wed Jul 27 01:12:34 2005 +++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Tue Aug 2 14:16:58 2005 @@ -46,6 +46,7 @@ #include "llvm/Support/Debug.h" #include "llvm/Support/GetElementPtrTypeIterator.h" #include "llvm/Support/InstVisitor.h" +#include "llvm/Support/MathExtras.h" #include "llvm/Support/PatternMatch.h" #include "llvm/ADT/DepthFirstIterator.h" #include "llvm/ADT/Statistic.h" @@ -361,19 +362,6 @@ return false; } -// Log2 - Calculate the log base 2 for the specified value if it is exactly a -// power of 2. -static unsigned Log2(uint64_t Val) { - assert(Val > 1 && "Values 0 and 1 should be handled elsewhere!"); - unsigned Count = 0; - while (Val != 1) { - if (Val & 1) return 0; // Multiple bits set? - Val >>= 1; - ++Count; - } - return Count; -} - // AddOne, SubOne - Add or subtract a constant one from an integer constant... static ConstantInt *AddOne(ConstantInt *C) { return cast(ConstantExpr::getAdd(C, @@ -934,9 +922,11 @@ return BinaryOperator::createNeg(Op0, I.getName()); int64_t Val = (int64_t)cast(CI)->getRawValue(); - if (uint64_t C = Log2(Val)) // Replace X*(2^C) with X << C + if (isPowerOf2_64(Val)) { // Replace X*(2^C) with X << C + uint64_t C = Log2_64(Val); return new ShiftInst(Instruction::Shl, Op0, ConstantUInt::get(Type::UByteTy, C)); + } } else if (ConstantFP *Op1F = dyn_cast(Op1)) { if (Op1F->isNullValue()) return ReplaceInstUsesWith(I, Op1); @@ -1039,9 +1029,11 @@ // if so, convert to a right shift. if (ConstantUInt *C = dyn_cast(RHS)) if (uint64_t Val = C->getValue()) // Don't break X / 0 - if (uint64_t C = Log2(Val)) + if (isPowerOf2_64(Val)) { + uint64_t C = Log2_64(Val); return new ShiftInst(Instruction::Shr, Op0, ConstantUInt::get(Type::UByteTy, C)); + } // -X/C -> X/-C if (RHS->getType()->isSigned()) @@ -1072,9 +1064,8 @@ } uint64_t TVA = STO->getValue(), FVA = SFO->getValue(); - unsigned TSA = 0, FSA = 0; - if ((TVA == 1 || (TSA = Log2(TVA))) && // Log2 fails for 0 & 1. - (FVA == 1 || (FSA = Log2(FVA)))) { + if (isPowerOf2_64(TVA) && isPowerOf2_64(FVA)) { + unsigned TSA = Log2_64(TVA), FSA = Log2_64(FVA); Constant *TC = ConstantUInt::get(Type::UByteTy, TSA); Instruction *TSI = new ShiftInst(Instruction::Shr, Op0, TC, SI->getName()+".t"); @@ -2777,9 +2768,10 @@ // If we have a signed (X % (2^c)) == 0, turn it into an unsigned one. if (CI->isNullValue() && isa(BO->getOperand(1)) && BO->hasOneUse() && - cast(BO->getOperand(1))->getValue() > 1) - if (unsigned L2 = - Log2(cast(BO->getOperand(1))->getValue())) { + cast(BO->getOperand(1))->getValue() > 1) { + int64_t V = cast(BO->getOperand(1))->getValue(); + if (isPowerOf2_64(V)) { + unsigned L2 = Log2_64(V); const Type *UTy = BO->getType()->getUnsignedVersion(); Value *NewX = InsertNewInstBefore(new CastInst(BO->getOperand(0), UTy, "tmp"), I); @@ -2789,6 +2781,7 @@ return BinaryOperator::create(I.getOpcode(), NewRem, Constant::getNullValue(UTy)); } + } break; case Instruction::Add: @@ -3638,7 +3631,7 @@ if (match(Op0, m_And(m_Value(), m_ConstantInt(AndRHS)))) if (AndRHS->getRawValue() && (AndRHS->getRawValue() & (AndRHS->getRawValue()-1)) == 0) { - unsigned ShiftAmt = Log2(AndRHS->getRawValue()); + unsigned ShiftAmt = Log2_64(AndRHS->getRawValue()); // Perform an unsigned shr by shiftamt. Convert input to // unsigned if it is signed. Value *In = Op0; From lattner at cs.uiuc.edu Tue Aug 2 14:22:02 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue, 2 Aug 2005 14:22:02 -0500 Subject: [llvm-commits] CVS: llvm/include/llvm/Support/MathExtras.h Message-ID: <200508021922.OAA07557@zion.cs.uiuc.edu> Changes in directory llvm/include/llvm/Support: MathExtras.h updated: 1.17 -> 1.18 --- Log message: Fix the non-gcc 4.0 path to compile --- Diffs of the changes: (+7 -5) MathExtras.h | 12 +++++++----- 1 files changed, 7 insertions(+), 5 deletions(-) Index: llvm/include/llvm/Support/MathExtras.h diff -u llvm/include/llvm/Support/MathExtras.h:1.17 llvm/include/llvm/Support/MathExtras.h:1.18 --- llvm/include/llvm/Support/MathExtras.h:1.17 Tue Aug 2 14:15:30 2005 +++ llvm/include/llvm/Support/MathExtras.h Tue Aug 2 14:21:51 2005 @@ -88,7 +88,7 @@ // PowerPC is defined for __builtin_clz(0) #if defined(__ppc__) || defined(__ppc64__) if (!Value) return 32; -#endif + #endif Count = __builtin_clz(Value); #else if (!Value) return 32; @@ -117,7 +117,8 @@ if (!Value) return 64; #endif Count = __builtin_clzll(Value); - #elif sizeof(long) == sizeof(int64_t) + #else + if (sizeof(long) == sizeof(int64_t)) { if (!Value) return 64; Count = 0; // bisecton method for count leading zeros @@ -127,8 +128,8 @@ Count |= Shift; Value = Tmp; } -} - #else + } + } else { // get hi portion unsigned Hi = Hi_32(Value); @@ -142,7 +143,8 @@ // same as 32 bit value Count = CountLeadingZeros_32(Lo); } - #endif + } +#endif return Count; } From lattner at cs.uiuc.edu Tue Aug 2 14:25:16 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue, 2 Aug 2005 14:25:16 -0500 Subject: [llvm-commits] CVS: llvm/lib/Target/IA64/IA64ISelPattern.cpp Message-ID: <200508021925.OAA07678@zion.cs.uiuc.edu> Changes in directory llvm/lib/Target/IA64: IA64ISelPattern.cpp updated: 1.50 -> 1.51 --- Log message: Update to use the new MathExtras.h support for log2 computation. Patch contributed by Jim Laskey! --- Diffs of the changes: (+4 -25) IA64ISelPattern.cpp | 29 ++++------------------------- 1 files changed, 4 insertions(+), 25 deletions(-) Index: llvm/lib/Target/IA64/IA64ISelPattern.cpp diff -u llvm/lib/Target/IA64/IA64ISelPattern.cpp:1.50 llvm/lib/Target/IA64/IA64ISelPattern.cpp:1.51 --- llvm/lib/Target/IA64/IA64ISelPattern.cpp:1.50 Wed Jul 27 01:12:33 2005 +++ llvm/lib/Target/IA64/IA64ISelPattern.cpp Tue Aug 2 14:25:03 2005 @@ -847,29 +847,6 @@ return finalresult; } -/// ExactLog2 - This function solves for (Val == 1 << (N-1)) and returns N. It -/// returns zero when the input is not exactly a power of two. -static unsigned ExactLog2(uint64_t Val) { - if (Val == 0 || (Val & (Val-1))) return 0; - unsigned Count = 0; - while (Val != 1) { - Val >>= 1; - ++Count; - } - return Count; -} - -/// ExactLog2sub1 - This function solves for (Val == (1 << (N-1))-1) -/// and returns N. It returns 666 if Val is not 2^n -1 for some n. -static unsigned ExactLog2sub1(uint64_t Val) { - unsigned int n; - for(n=0; n<64; n++) { - if(Val==(uint64_t)((1LL<(N)->getSignExtended(); - if ((Imm = ExactLog2(v))) { // if a division by a power of two, say so + if (isPowerOf2_64(v)) { // if a division by a power of two, say so + Imm = Log2_64(v); return 1; } @@ -895,7 +873,8 @@ int64_t v = (int64_t)cast(N)->getSignExtended(); - if ((Imm = ExactLog2sub1(v))!=666) { // if ANDing with ((2^n)-1) for some n + if (isMask_64(v)) { // if ANDing with ((2^n)-1) for some n + Imm = Log2_64(v); return 1; // say so } From lattner at cs.uiuc.edu Tue Aug 2 14:25:16 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue, 2 Aug 2005 14:25:16 -0500 Subject: [llvm-commits] CVS: llvm/lib/Target/Alpha/AlphaISelPattern.cpp Message-ID: <200508021925.OAA07672@zion.cs.uiuc.edu> Changes in directory llvm/lib/Target/Alpha: AlphaISelPattern.cpp updated: 1.157 -> 1.158 --- Log message: Update to use the new MathExtras.h support for log2 computation. Patch contributed by Jim Laskey! --- Diffs of the changes: (+0 -14) AlphaISelPattern.cpp | 14 -------------- 1 files changed, 14 deletions(-) Index: llvm/lib/Target/Alpha/AlphaISelPattern.cpp diff -u llvm/lib/Target/Alpha/AlphaISelPattern.cpp:1.157 llvm/lib/Target/Alpha/AlphaISelPattern.cpp:1.158 --- llvm/lib/Target/Alpha/AlphaISelPattern.cpp:1.157 Mon Aug 1 12:47:28 2005 +++ llvm/lib/Target/Alpha/AlphaISelPattern.cpp Tue Aug 2 14:25:03 2005 @@ -801,20 +801,6 @@ return Q; } -//From PPC32 -/// ExactLog2 - This function solves for (Val == 1 << (N-1)) and returns N. It -/// returns zero when the input is not exactly a power of two. -static unsigned ExactLog2(uint64_t Val) { - if (Val == 0 || (Val & (Val-1))) return 0; - unsigned Count = 0; - while (Val != 1) { - Val >>= 1; - ++Count; - } - return Count; -} - - //These describe LDAx static const int IMM_LOW = -32768; static const int IMM_HIGH = 32767; From lattner at cs.uiuc.edu Tue Aug 2 14:25:17 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue, 2 Aug 2005 14:25:17 -0500 Subject: [llvm-commits] CVS: llvm/lib/Target/SparcV9/SparcV9BurgISel.cpp Message-ID: <200508021925.OAA07695@zion.cs.uiuc.edu> Changes in directory llvm/lib/Target/SparcV9: SparcV9BurgISel.cpp updated: 1.24 -> 1.25 --- Log message: Update to use the new MathExtras.h support for log2 computation. Patch contributed by Jim Laskey! --- Diffs of the changes: (+5 -5) SparcV9BurgISel.cpp | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-) Index: llvm/lib/Target/SparcV9/SparcV9BurgISel.cpp diff -u llvm/lib/Target/SparcV9/SparcV9BurgISel.cpp:1.24 llvm/lib/Target/SparcV9/SparcV9BurgISel.cpp:1.25 --- llvm/lib/Target/SparcV9/SparcV9BurgISel.cpp:1.24 Wed Jul 27 01:12:33 2005 +++ llvm/lib/Target/SparcV9/SparcV9BurgISel.cpp Tue Aug 2 14:25:03 2005 @@ -2306,7 +2306,6 @@ constOp->getType(), isValidConst); if (isValidConst) { - unsigned pow; bool needNeg = false; if (C < 0) { needNeg = true; @@ -2323,7 +2322,8 @@ else M = BuildMI(V9::ADDr,3).addReg(lval).addMReg(Zero).addRegDef(destVal); mvec.push_back(M); - } else if (isPowerOf2(C, pow)) { + } else if (isPowerOf2_64(C)) { + unsigned pow = Log2_64(C); if(!needNeg) { unsigned opSize = target.getTargetData().getTypeSize(resultType); MachineOpCode opCode = (opSize <= 32)? V9::SLLr5 : V9::SLLXr6; @@ -2464,7 +2464,6 @@ const Type* resultType = instrNode->getInstruction()->getType(); if (resultType->isInteger()) { - unsigned pow; bool isValidConst; int64_t C = (int64_t) ConvertConstantToIntType(target, constOp, constOp->getType(), @@ -2479,7 +2478,8 @@ if (C == 1) { mvec.push_back(BuildMI(V9::ADDr, 3).addReg(LHS).addMReg(ZeroReg) .addRegDef(destVal)); - } else if (isPowerOf2(C, pow)) { + } else if (isPowerOf2_64(C)) { + unsigned pow = Log2_64(C); unsigned opCode; Value* shiftOperand; unsigned opSize = target.getTargetData().getTypeSize(resultType); @@ -2539,7 +2539,7 @@ .addRegDef(destVal)); } - if (needNeg && (C == 1 || isPowerOf2(C, pow))) { + if (needNeg && (C == 1 || isPowerOf2_64(C))) { // insert after the instr to flip the sign mvec.push_back(CreateIntNegInstruction(target, destVal)); } From lattner at cs.uiuc.edu Tue Aug 2 14:25:17 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue, 2 Aug 2005 14:25:17 -0500 Subject: [llvm-commits] CVS: llvm/lib/Target/X86/X86ISelPattern.cpp X86ISelSimple.cpp Message-ID: <200508021925.OAA07696@zion.cs.uiuc.edu> Changes in directory llvm/lib/Target/X86: X86ISelPattern.cpp updated: 1.162 -> 1.163 X86ISelSimple.cpp updated: 1.321 -> 1.322 --- Log message: Update to use the new MathExtras.h support for log2 computation. Patch contributed by Jim Laskey! --- Diffs of the changes: (+14 -23) X86ISelPattern.cpp | 2 +- X86ISelSimple.cpp | 35 +++++++++++++---------------------- 2 files changed, 14 insertions(+), 23 deletions(-) Index: llvm/lib/Target/X86/X86ISelPattern.cpp diff -u llvm/lib/Target/X86/X86ISelPattern.cpp:1.162 llvm/lib/Target/X86/X86ISelPattern.cpp:1.163 --- llvm/lib/Target/X86/X86ISelPattern.cpp:1.162 Sat Jul 30 13:33:25 2005 +++ llvm/lib/Target/X86/X86ISelPattern.cpp Tue Aug 2 14:25:03 2005 @@ -3023,7 +3023,7 @@ RHS = -RHS; } if (RHS && (RHS & (RHS-1)) == 0) { // Signed division by power of 2? - unsigned Log = log2(RHS); + unsigned Log = Log2_32(RHS); unsigned SAROpc, SHROpc, ADDOpc, NEGOpc; switch (N.getValueType()) { default: assert("Unknown type to signed divide!"); Index: llvm/lib/Target/X86/X86ISelSimple.cpp diff -u llvm/lib/Target/X86/X86ISelSimple.cpp:1.321 llvm/lib/Target/X86/X86ISelSimple.cpp:1.322 --- llvm/lib/Target/X86/X86ISelSimple.cpp:1.321 Wed Jul 27 01:12:34 2005 +++ llvm/lib/Target/X86/X86ISelSimple.cpp Tue Aug 2 14:25:03 2005 @@ -29,6 +29,7 @@ #include "llvm/Target/TargetOptions.h" #include "llvm/Support/GetElementPtrTypeIterator.h" #include "llvm/Support/InstVisitor.h" +#include "llvm/Support/MathExtras.h" #include "llvm/ADT/Statistic.h" using namespace llvm; @@ -2496,19 +2497,6 @@ } } -// ExactLog2 - This function solves for (Val == 1 << (N-1)) and returns N. It -// returns zero when the input is not exactly a power of two. -static unsigned ExactLog2(unsigned Val) { - if (Val == 0 || (Val & (Val-1))) return 0; - unsigned Count = 0; - while (Val != 1) { - Val >>= 1; - ++Count; - } - return Count+1; -} - - /// doMultiplyConst - This function is specialized to efficiently codegen an 8, /// 16, or 32-bit integer multiply by a constant. void X86ISel::doMultiplyConst(MachineBasicBlock *MBB, @@ -2573,35 +2561,37 @@ } // If the element size is exactly a power of 2, use a shift to get it. - if (unsigned Shift = ExactLog2(ConstRHS)) { + if (isPowerOf2_32(ConstRHS)) { + unsigned Shift = Log2_32(ConstRHS); switch (Class) { default: assert(0 && "Unknown class for this function!"); case cByte: - BuildMI(*MBB, IP, X86::SHL8ri,2, DestReg).addReg(op0Reg).addImm(Shift-1); + BuildMI(*MBB, IP, X86::SHL8ri,2, DestReg).addReg(op0Reg).addImm(Shift); return; case cShort: - BuildMI(*MBB, IP, X86::SHL16ri,2, DestReg).addReg(op0Reg).addImm(Shift-1); + BuildMI(*MBB, IP, X86::SHL16ri,2, DestReg).addReg(op0Reg).addImm(Shift); return; case cInt: - BuildMI(*MBB, IP, X86::SHL32ri,2, DestReg).addReg(op0Reg).addImm(Shift-1); + BuildMI(*MBB, IP, X86::SHL32ri,2, DestReg).addReg(op0Reg).addImm(Shift); return; } } // If the element size is a negative power of 2, use a shift/neg to get it. - if (unsigned Shift = ExactLog2(-ConstRHS)) { + if (isPowerOf2_32(-ConstRHS)) { + unsigned Shift = Log2_32(-ConstRHS); TmpReg = makeAnotherReg(DestTy); BuildMI(*MBB, IP, NEGrTab[Class], 1, TmpReg).addReg(op0Reg); switch (Class) { default: assert(0 && "Unknown class for this function!"); case cByte: - BuildMI(*MBB, IP, X86::SHL8ri,2, DestReg).addReg(TmpReg).addImm(Shift-1); + BuildMI(*MBB, IP, X86::SHL8ri,2, DestReg).addReg(TmpReg).addImm(Shift); return; case cShort: - BuildMI(*MBB, IP, X86::SHL16ri,2, DestReg).addReg(TmpReg).addImm(Shift-1); + BuildMI(*MBB, IP, X86::SHL16ri,2, DestReg).addReg(TmpReg).addImm(Shift); return; case cInt: - BuildMI(*MBB, IP, X86::SHL32ri,2, DestReg).addReg(TmpReg).addImm(Shift-1); + BuildMI(*MBB, IP, X86::SHL32ri,2, DestReg).addReg(TmpReg).addImm(Shift); return; } } @@ -2917,7 +2907,8 @@ V = -V; isNeg = true; // Maybe it's a negative power of 2. } - if (unsigned Log = ExactLog2(V)) { + if (isPowerOf2_32(V)) { + unsigned Log = Log2_32(V); --Log; unsigned Op0Reg = getReg(Op0, BB, IP); unsigned TmpReg = makeAnotherReg(Op0->getType()); From lattner at cs.uiuc.edu Tue Aug 2 14:25:16 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue, 2 Aug 2005 14:25:16 -0500 Subject: [llvm-commits] CVS: llvm/lib/Target/TargetData.cpp Message-ID: <200508021925.OAA07676@zion.cs.uiuc.edu> Changes in directory llvm/lib/Target: TargetData.cpp updated: 1.56 -> 1.57 --- Log message: Update to use the new MathExtras.h support for log2 computation. Patch contributed by Jim Laskey! --- Diffs of the changes: (+1 -1) TargetData.cpp | 2 +- 1 files changed, 1 insertion(+), 1 deletion(-) Index: llvm/lib/Target/TargetData.cpp diff -u llvm/lib/Target/TargetData.cpp:1.56 llvm/lib/Target/TargetData.cpp:1.57 --- llvm/lib/Target/TargetData.cpp:1.56 Thu Apr 21 17:55:34 2005 +++ llvm/lib/Target/TargetData.cpp Tue Aug 2 14:25:02 2005 @@ -229,7 +229,7 @@ unsigned char TargetData::getTypeAlignmentShift(const Type *Ty) const { unsigned Align = getTypeAlignment(Ty); assert(!(Align & (Align-1)) && "Alignment is not a power of two!"); - return log2(Align); + return Log2_32(Align); } /// getIntPtrType - Return an unsigned integer type that is the same size or From lattner at cs.uiuc.edu Tue Aug 2 14:26:17 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue, 2 Aug 2005 14:26:17 -0500 Subject: [llvm-commits] CVS: llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp Message-ID: <200508021926.OAA07757@zion.cs.uiuc.edu> Changes in directory llvm/lib/CodeGen/SelectionDAG: SelectionDAG.cpp updated: 1.126 -> 1.127 --- Log message: Update to use the new MathExtras.h support for log2 computation. Patch contributed by Jim Laskey! --- Diffs of the changes: (+6 -14) SelectionDAG.cpp | 20 ++++++-------------- 1 files changed, 6 insertions(+), 14 deletions(-) Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp diff -u llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1.126 llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1.127 --- llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1.126 Wed Jul 27 01:12:33 2005 +++ llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp Tue Aug 2 14:26:06 2005 @@ -16,6 +16,7 @@ #include "llvm/GlobalValue.h" #include "llvm/Assembly/Writer.h" #include "llvm/CodeGen/MachineBasicBlock.h" +#include "llvm/Support/MathExtras.h" #include "llvm/Target/TargetLowering.h" #include #include @@ -45,15 +46,6 @@ } } -static unsigned ExactLog2(uint64_t Val) { - unsigned Count = 0; - while (Val != 1) { - Val >>= 1; - ++Count; - } - return Count; -} - // isInvertibleForFree - Return true if there is no cost to emitting the logical // inverse of this node. static bool isInvertibleForFree(SDOperand N) { @@ -527,7 +519,7 @@ // Perform the xform if the AND RHS is a single bit. if ((AndRHS->getValue() & (AndRHS->getValue()-1)) == 0) { return getNode(ISD::SRL, VT, N1, - getConstant(ExactLog2(AndRHS->getValue()), + getConstant(Log2_64(AndRHS->getValue()), TLI.getShiftAmountTy())); } } else if (Cond == ISD::SETEQ && C2 == AndRHS->getValue()) { @@ -535,7 +527,7 @@ // Perform the xform if C2 is a single bit. if ((C2 & (C2-1)) == 0) { return getNode(ISD::SRL, VT, N1, - getConstant(ExactLog2(C2),TLI.getShiftAmountTy())); + getConstant(Log2_64(C2),TLI.getShiftAmountTy())); } } } @@ -956,7 +948,7 @@ // FIXME: Move this to the DAG combiner when it exists. if ((C2 & C2-1) == 0) { - SDOperand ShAmt = getConstant(ExactLog2(C2), TLI.getShiftAmountTy()); + SDOperand ShAmt = getConstant(Log2_64(C2), TLI.getShiftAmountTy()); return getNode(ISD::SHL, VT, N1, ShAmt); } break; @@ -974,7 +966,7 @@ case ISD::UDIV: // FIXME: Move this to the DAG combiner when it exists. if ((C2 & C2-1) == 0 && C2) { - SDOperand ShAmt = getConstant(ExactLog2(C2), TLI.getShiftAmountTy()); + SDOperand ShAmt = getConstant(Log2_64(C2), TLI.getShiftAmountTy()); return getNode(ISD::SRL, VT, N1, ShAmt); } break; @@ -1410,7 +1402,7 @@ // exists. if (ConstantSDNode *AC = dyn_cast(N2)) if ((AC->getValue() & (AC->getValue()-1)) == 0) { - unsigned ShCtV = ExactLog2(AC->getValue()); + unsigned ShCtV = Log2_64(AC->getValue()); ShCtV = MVT::getSizeInBits(XType)-ShCtV-1; SDOperand ShCt = getConstant(ShCtV, TLI.getShiftAmountTy()); SDOperand Shift = getNode(ISD::SRL, XType, From lattner at cs.uiuc.edu Tue Aug 2 14:31:06 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue, 2 Aug 2005 14:31:06 -0500 Subject: [llvm-commits] CVS: llvm/lib/Target/PowerPC/PPC32ISelPattern.cpp Message-ID: <200508021931.OAA09095@zion.cs.uiuc.edu> Changes in directory llvm/lib/Target/PowerPC: PPC32ISelPattern.cpp updated: 1.111 -> 1.112 --- Log message: This hunk accidentally got dropped. Patch by Jim Laskey --- Diffs of the changes: (+0 -67) PPC32ISelPattern.cpp | 67 --------------------------------------------------- 1 files changed, 67 deletions(-) Index: llvm/lib/Target/PowerPC/PPC32ISelPattern.cpp diff -u llvm/lib/Target/PowerPC/PPC32ISelPattern.cpp:1.111 llvm/lib/Target/PowerPC/PPC32ISelPattern.cpp:1.112 --- llvm/lib/Target/PowerPC/PPC32ISelPattern.cpp:1.111 Tue Aug 2 14:25:03 2005 +++ llvm/lib/Target/PowerPC/PPC32ISelPattern.cpp Tue Aug 2 14:30:55 2005 @@ -601,73 +601,6 @@ } }; -/// ExactLog2 - This function solves for (Val == 1 << (N-1)) and returns N. It -/// returns zero when the input is not exactly a power of two. -static unsigned ExactLog2(unsigned Val) { - if (Val == 0 || (Val & (Val-1))) return 0; - unsigned Count = 0; - while (Val != 1) { - Val >>= 1; - ++Count; - } - return Count; -} - -// IsRunOfOnes - returns true if Val consists of one contiguous run of 1's with -// any number of 0's on either side. the 1's are allowed to wrap from LSB to -// MSB. so 0x000FFF0, 0x0000FFFF, and 0xFF0000FF are all runs. 0x0F0F0000 is -// not, since all 1's are not contiguous. -static bool IsRunOfOnes(unsigned Val, unsigned &MB, unsigned &ME) { - bool isRun = true; - MB = 0; - ME = 0; - - // look for first set bit - int i = 0; - for (; i < 32; i++) { - if ((Val & (1 << (31 - i))) != 0) { - MB = i; - ME = i; - break; - } - } - - // look for last set bit - for (; i < 32; i++) { - if ((Val & (1 << (31 - i))) == 0) - break; - ME = i; - } - - // look for next set bit - for (; i < 32; i++) { - if ((Val & (1 << (31 - i))) != 0) - break; - } - - // if we exhausted all the bits, we found a match at this point for 0*1*0* - if (i == 32) - return true; - - // since we just encountered more 1's, if it doesn't wrap around to the - // most significant bit of the word, then we did not find a match to 1*0*1* so - // exit. - if (MB != 0) - return false; - - // look for last set bit - for (MB = i; i < 32; i++) { - if ((Val & (1 << (31 - i))) == 0) - break; - } - - // if we exhausted all the bits, then we found a match for 1*0*1*, otherwise, - // the value is not a run of ones. - if (i == 32) - return true; - return false; -} - /// getImmediateForOpcode - This method returns a value indicating whether /// the ConstantSDNode N can be used as an immediate to Opcode. The return /// values are either 0, 1 or 2. 0 indicates that either N is not a From lattner at cs.uiuc.edu Tue Aug 2 14:35:41 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue, 2 Aug 2005 14:35:41 -0500 Subject: [llvm-commits] CVS: llvm/lib/Target/Alpha/AlphaISelPattern.cpp Message-ID: <200508021935.OAA09159@zion.cs.uiuc.edu> Changes in directory llvm/lib/Target/Alpha: AlphaISelPattern.cpp updated: 1.158 -> 1.159 --- Log message: one more hunk that got dropped --- Diffs of the changes: (+2 -3) AlphaISelPattern.cpp | 5 ++--- 1 files changed, 2 insertions(+), 3 deletions(-) Index: llvm/lib/Target/Alpha/AlphaISelPattern.cpp diff -u llvm/lib/Target/Alpha/AlphaISelPattern.cpp:1.158 llvm/lib/Target/Alpha/AlphaISelPattern.cpp:1.159 --- llvm/lib/Target/Alpha/AlphaISelPattern.cpp:1.158 Tue Aug 2 14:25:03 2005 +++ llvm/lib/Target/Alpha/AlphaISelPattern.cpp Tue Aug 2 14:35:29 2005 @@ -1833,9 +1833,8 @@ //check if we can convert into a shift! if ((CSD = dyn_cast(N.getOperand(1).Val)) && (int64_t)CSD->getSignExtended() != 0 && - ExactLog2(llabs(CSD->getSignExtended())) != 0) - { - unsigned k = ExactLog2(llabs(CSD->getSignExtended())); + isPowerOf2_64(llabs(CSD->getSignExtended()))) { + unsigned k = Log2_64(llabs(CSD->getSignExtended())); Tmp1 = SelectExpr(N.getOperand(0)); if (k == 1) Tmp2 = Tmp1; From lattner at cs.uiuc.edu Tue Aug 2 15:06:30 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue, 2 Aug 2005 15:06:30 -0500 Subject: [llvm-commits] CVS: llvm/include/llvm/Support/MathExtras.h Message-ID: <200508022006.PAA10180@zion.cs.uiuc.edu> Changes in directory llvm/include/llvm/Support: MathExtras.h updated: 1.18 -> 1.19 --- Log message: Fix inverted conditionals --- Diffs of the changes: (+2 -2) MathExtras.h | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) Index: llvm/include/llvm/Support/MathExtras.h diff -u llvm/include/llvm/Support/MathExtras.h:1.18 llvm/include/llvm/Support/MathExtras.h:1.19 --- llvm/include/llvm/Support/MathExtras.h:1.18 Tue Aug 2 14:21:51 2005 +++ llvm/include/llvm/Support/MathExtras.h Tue Aug 2 15:06:18 2005 @@ -86,7 +86,7 @@ unsigned Count; // result #if __GNUC__ >= 4 // PowerPC is defined for __builtin_clz(0) - #if defined(__ppc__) || defined(__ppc64__) + #if !defined(__ppc__) && !defined(__ppc64__) if (!Value) return 32; #endif Count = __builtin_clz(Value); @@ -113,7 +113,7 @@ unsigned Count; // result #if __GNUC__ >= 4 // PowerPC is defined for __builtin_clzll(0) - #if defined(__ppc__) || defined(__ppc64__) + #if !defined(__ppc__) && !defined(__ppc64__) if (!Value) return 64; #endif Count = __builtin_clzll(Value); From lattner at cs.uiuc.edu Tue Aug 2 15:21:45 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue, 2 Aug 2005 15:21:45 -0500 Subject: [llvm-commits] CVS: llvm/include/llvm/Support/MathExtras.h Message-ID: <200508022021.PAA10726@zion.cs.uiuc.edu> Changes in directory llvm/include/llvm/Support: MathExtras.h updated: 1.19 -> 1.20 --- Log message: Fix the non-gcc 4.0 paths for countleadingzeros Patch fixed by Jim Laskey --- Diffs of the changes: (+35 -29) MathExtras.h | 64 ++++++++++++++++++++++++++++++++--------------------------- 1 files changed, 35 insertions(+), 29 deletions(-) Index: llvm/include/llvm/Support/MathExtras.h diff -u llvm/include/llvm/Support/MathExtras.h:1.19 llvm/include/llvm/Support/MathExtras.h:1.20 --- llvm/include/llvm/Support/MathExtras.h:1.19 Tue Aug 2 15:06:18 2005 +++ llvm/include/llvm/Support/MathExtras.h Tue Aug 2 15:21:33 2005 @@ -72,36 +72,41 @@ return Value && !(Value & (Value - 1)); } -// isPowerOf2_64 - This function returns true if the argument is a power of two > 0 -// (64 bit edition.) +// isPowerOf2_64 - This function returns true if the argument is a power of two +// > 0 (64 bit edition.) inline bool isPowerOf2_64(uint64_t Value) { return Value && !(Value & (Value - 1LL)); } +// CountLeadingZeros_32 - this function performs the platform optimal form of +// counting the number of zeros from the most significant bit to the first one +// bit. Ex. CountLeadingZeros_32(0x00F000FF) == 8. +// Returns 32 if the word is zero. // CountLeadingZeros_32 - this function performs the platform optimal form -// of counting the number of zeros from the most significant bit to the first one bit. -// Ex. CountLeadingZeros_32(0x00F000FF) == 8. +// of counting the number of zeros from the most significant bit to the first +// one bit. Ex. CountLeadingZeros_32(0x00F000FF) == 8. // Returns 32 if the word is zero. inline unsigned CountLeadingZeros_32(unsigned Value) { unsigned Count; // result - #if __GNUC__ >= 4 - // PowerPC is defined for __builtin_clz(0) - #if !defined(__ppc__) && !defined(__ppc64__) - if (!Value) return 32; - #endif - Count = __builtin_clz(Value); - #else - if (!Value) return 32; - Count = 0; - // bisecton method for count leading zeros - for (unsigned Shift = 32 >> 1; Shift; Shift >>= 1) { - unsigned Tmp = Value >> Shift; - if (Tmp) { - Count |= Shift; - Value = Tmp; - } +#if __GNUC__ >= 4 + // PowerPC is defined for __builtin_clz(0) +#if !defined(__ppc__) && !defined(__ppc64__) + if (!Value) return 32; +#endif + Count = __builtin_clz(Value); +#else + if (!Value) return 32; + Count = 0; + // bisecton method for count leading zeros + for (unsigned Shift = 32 >> 1; Shift; Shift >>= 1) { + unsigned Tmp = Value >> Shift; + if (Tmp) { + Value = Tmp; + } else { + Count |= Shift; } - #endif + } +#endif return Count; } @@ -111,13 +116,13 @@ // Returns 64 if the word is zero. inline unsigned CountLeadingZeros_64(uint64_t Value) { unsigned Count; // result - #if __GNUC__ >= 4 - // PowerPC is defined for __builtin_clzll(0) - #if !defined(__ppc__) && !defined(__ppc64__) - if (!Value) return 64; - #endif - Count = __builtin_clzll(Value); - #else +#if __GNUC__ >= 4 + // PowerPC is defined for __builtin_clzll(0) +#if defined(__ppc__) || defined(__ppc64__) + if (!Value) return 64; +#endif + Count = __builtin_clzll(Value); +#else if (sizeof(long) == sizeof(int64_t)) { if (!Value) return 64; Count = 0; @@ -125,8 +130,9 @@ for (uint64_t Shift = 64 >> 1; Shift; Shift >>= 1) { uint64_t Tmp = Value >> Shift; if (Tmp) { - Count |= Shift; Value = Tmp; + } else { + Count |= Shift; } } } else { From lattner at cs.uiuc.edu Tue Aug 2 17:04:12 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue, 2 Aug 2005 17:04:12 -0500 Subject: [llvm-commits] CVS: llvm-test/RunSafely.sh Message-ID: <200508022204.RAA14986@zion.cs.uiuc.edu> Changes in directory llvm-test: RunSafely.sh updated: 1.18 -> 1.19 --- Log message: Prevent llvm-test from filling up /cores with giant core files on darwin. --- Diffs of the changes: (+9 -0) RunSafely.sh | 9 +++++++++ 1 files changed, 9 insertions(+) Index: llvm-test/RunSafely.sh diff -u llvm-test/RunSafely.sh:1.18 llvm-test/RunSafely.sh:1.19 --- llvm-test/RunSafely.sh:1.18 Thu Jul 28 12:02:07 2005 +++ llvm-test/RunSafely.sh Tue Aug 2 17:04:00 2005 @@ -23,6 +23,15 @@ case $SYSTEM in CYGWIN*) ;; + Darwin*) + # Disable core file emission, the script doesn't find it anyway because it is put + # into /cores. + ulimit -c 0 + ulimit -t $ULIMIT + # To prevent infinite loops which fill up the disk, specify a limit on size of + # files being output by the tests. 10 MB should be enough for anybody. ;) + ulimit -f 10485760 + ;; *) ulimit -t $ULIMIT ulimit -c unlimited From lattner at cs.uiuc.edu Tue Aug 2 17:04:42 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue, 2 Aug 2005 17:04:42 -0500 Subject: [llvm-commits] CVS: llvm-test/RunSafelyAndStable.sh Message-ID: <200508022204.RAA15019@zion.cs.uiuc.edu> Changes in directory llvm-test: RunSafelyAndStable.sh updated: 1.4 -> 1.5 --- Log message: Sync up with RunSafely.sh, adding support for cygwin and darwin --- Diffs of the changes: (+21 -6) RunSafelyAndStable.sh | 27 +++++++++++++++++++++------ 1 files changed, 21 insertions(+), 6 deletions(-) Index: llvm-test/RunSafelyAndStable.sh diff -u llvm-test/RunSafelyAndStable.sh:1.4 llvm-test/RunSafelyAndStable.sh:1.5 --- llvm-test/RunSafelyAndStable.sh:1.4 Thu Jul 28 12:02:07 2005 +++ llvm-test/RunSafelyAndStable.sh Tue Aug 2 17:04:31 2005 @@ -21,12 +21,27 @@ PROGRAM=$4 shift 4 -ulimit -t $ULIMIT -rm -f core core.* -ulimit -c unlimited -# To prevent infinite loops which fill up the disk, specify a limit on size of -# files being output by the tests. 10 MB should be enough for anybody. ;) -ulimit -f 10485760 +SYSTEM=`uname -s` + +case $SYSTEM in + CYGWIN*) + ;; + Darwin*) + # Disable core file emission, the script doesn't find it anyway because it is put + # into /cores. + ulimit -c 0 + ulimit -t $ULIMIT + # To prevent infinite loops which fill up the disk, specify a limit on size of + # files being output by the tests. 10 MB should be enough for anybody. ;) + ulimit -f 10485760 + ;; + *) + ulimit -t $ULIMIT + ulimit -c unlimited + # To prevent infinite loops which fill up the disk, specify a limit on size of + # files being output by the tests. 10 MB should be enough for anybody. ;) + ulimit -f 10485760 +esac # # Run the command, timing its execution. From lattner at cs.uiuc.edu Tue Aug 2 17:07:49 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue, 2 Aug 2005 17:07:49 -0500 Subject: [llvm-commits] CVS: llvm/tools/gccld/GenerateCode.cpp gccld.cpp gccld.h Message-ID: <200508022207.RAA15091@zion.cs.uiuc.edu> Changes in directory llvm/tools/gccld: GenerateCode.cpp updated: 1.50 -> 1.51 gccld.cpp updated: 1.102 -> 1.103 gccld.h updated: 1.16 -> 1.17 --- Log message: Pass -export-dynamic to gcc when compiling with -native and the link is performed with -export-dynamic (aka. -disable-internalize). Patch by Nicholas Riley! --- Diffs of the changes: (+10 -8) GenerateCode.cpp | 9 +++++---- gccld.cpp | 8 ++++---- gccld.h | 1 + 3 files changed, 10 insertions(+), 8 deletions(-) Index: llvm/tools/gccld/GenerateCode.cpp diff -u llvm/tools/gccld/GenerateCode.cpp:1.50 llvm/tools/gccld/GenerateCode.cpp:1.51 --- llvm/tools/gccld/GenerateCode.cpp:1.50 Fri Jul 8 11:48:52 2005 +++ llvm/tools/gccld/GenerateCode.cpp Tue Aug 2 17:07:38 2005 @@ -325,8 +325,7 @@ return sys::Program::ExecuteAndWait(llc, &args[0]); } -/// GenerateAssembly - generates a native assembly language source file from the -/// specified bytecode file. +/// GenerateCFile - generates a C source file from the specified bytecode file. int llvm::GenerateCFile(const std::string &OutputFile, const std::string &InputFile, const sys::Path &llc, @@ -344,8 +343,8 @@ return sys::Program::ExecuteAndWait(llc, &args[0]); } -/// GenerateNative - generates a native assembly language source file from the -/// specified assembly source file. +/// GenerateNative - generates a native executable file from the specified +/// assembly source file. /// /// Inputs: /// InputFilename - The name of the output bytecode file. @@ -365,6 +364,7 @@ const std::vector &Libraries, const sys::Path &gcc, char ** const envp, bool Shared, + bool ExportAllAsDynamic, const std::string &RPath, const std::string &SOName, bool Verbose) { @@ -400,6 +400,7 @@ args.push_back(InputFilename.c_str()); if (Shared) args.push_back("-shared"); + if (ExportAllAsDynamic) args.push_back("-export-dynamic"); if (!RPath.empty()) { std::string rp = "-Wl,-rpath," + RPath; args.push_back(rp.c_str()); Index: llvm/tools/gccld/gccld.cpp diff -u llvm/tools/gccld/gccld.cpp:1.102 llvm/tools/gccld/gccld.cpp:1.103 --- llvm/tools/gccld/gccld.cpp:1.102 Thu Jul 7 22:08:58 2005 +++ llvm/tools/gccld/gccld.cpp Tue Aug 2 17:07:38 2005 @@ -308,8 +308,8 @@ Verbose); if (Verbose) std::cout << "Generating Native Code\n"; GenerateNative(OutputFilename, AssemblyFile.toString(), - LibPaths, Libraries, gcc, envp, LinkAsLibrary, RPath, - SOName, Verbose); + LibPaths, Libraries, gcc, envp, LinkAsLibrary, + NoInternalize, RPath, SOName, Verbose); if (!SaveTemps) { // Remove the assembly language file. @@ -340,8 +340,8 @@ GenerateCFile(CFile.toString(), RealBytecodeOutput, llc, Verbose); if (Verbose) std::cout << "Generating Native Code\n"; GenerateNative(OutputFilename, CFile.toString(), - LibPaths, Libraries, gcc, envp, LinkAsLibrary, RPath, - SOName, Verbose); + LibPaths, Libraries, gcc, envp, LinkAsLibrary, + NoInternalize, RPath, SOName, Verbose); if (!SaveTemps) { // Remove the assembly language file. Index: llvm/tools/gccld/gccld.h diff -u llvm/tools/gccld/gccld.h:1.16 llvm/tools/gccld/gccld.h:1.17 --- llvm/tools/gccld/gccld.h:1.16 Thu Apr 21 18:59:28 2005 +++ llvm/tools/gccld/gccld.h Tue Aug 2 17:07:38 2005 @@ -45,6 +45,7 @@ const sys::Path &gcc, char ** const envp, bool Shared, + bool ExportAllAsDynamic, const std::string &RPath, const std::string &SOName, bool Verbose=false); From lattner at cs.uiuc.edu Tue Aug 2 17:10:33 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue, 2 Aug 2005 17:10:33 -0500 Subject: [llvm-commits] CVS: llvm/CREDITS.TXT Message-ID: <200508022210.RAA15132@zion.cs.uiuc.edu> Changes in directory llvm: CREDITS.TXT updated: 1.41 -> 1.42 --- Log message: Add a note, people are responsible for requesting that they be added to the file. --- Diffs of the changes: (+4 -3) CREDITS.TXT | 7 ++++--- 1 files changed, 4 insertions(+), 3 deletions(-) Index: llvm/CREDITS.TXT diff -u llvm/CREDITS.TXT:1.41 llvm/CREDITS.TXT:1.42 --- llvm/CREDITS.TXT:1.41 Sun May 15 16:38:32 2005 +++ llvm/CREDITS.TXT Tue Aug 2 17:10:21 2005 @@ -1,6 +1,7 @@ -Inspired by the CREDITS file from the Linux source tree, this file is, -likewise, at least a partial list of people who have contributed to the LLVM -project. The format and the next paragraph are stolen directly from that file. +This file is a partial list of people who have contributed to the LLVM +project. If you have contributed a patch or made some other contribution to +LLVM, please submit a patch to this file to add yourself, and it will be +done! The list is sorted by name and formatted to allow easy grepping and beautification by scripts. The fields are: name (N), email (E), web-address From lattner at cs.uiuc.edu Tue Aug 2 18:26:08 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue, 2 Aug 2005 18:26:08 -0500 Subject: [llvm-commits] CVS: llvm/tools/bugpoint/Miscompilation.cpp Message-ID: <200508022326.SAA15798@zion.cs.uiuc.edu> Changes in directory llvm/tools/bugpoint: Miscompilation.cpp updated: 1.70 -> 1.71 --- Log message: If the user interrupts bugpoint, don't extract loops --- Diffs of the changes: (+6 -2) Miscompilation.cpp | 8 ++++++-- 1 files changed, 6 insertions(+), 2 deletions(-) Index: llvm/tools/bugpoint/Miscompilation.cpp diff -u llvm/tools/bugpoint/Miscompilation.cpp:1.70 llvm/tools/bugpoint/Miscompilation.cpp:1.71 --- llvm/tools/bugpoint/Miscompilation.cpp:1.70 Mon Aug 1 21:16:17 2005 +++ llvm/tools/bugpoint/Miscompilation.cpp Tue Aug 2 18:25:56 2005 @@ -247,6 +247,8 @@ std::vector &MiscompiledFunctions) { bool MadeChange = false; while (1) { + if (BugpointIsInterrupted) return MadeChange; + Module *ToNotOptimize = CloneModule(BD.getProgram()); Module *ToOptimize = SplitFunctionsOutOfModule(ToNotOptimize, MiscompiledFunctions); @@ -506,7 +508,8 @@ // See if we can rip any loops out of the miscompiled functions and still // trigger the problem. - if (ExtractLoops(BD, TestFn, MiscompiledFunctions)) { + if (!BugpointIsInterrupted && + ExtractLoops(BD, TestFn, MiscompiledFunctions)) { // Okay, we extracted some loops and the problem still appears. See if we // can eliminate some of the created functions from being candidates. @@ -526,7 +529,8 @@ std::cout << '\n'; } - if (ExtractBlocks(BD, TestFn, MiscompiledFunctions)) { + if (!BugpointIsInterrupted && + ExtractBlocks(BD, TestFn, MiscompiledFunctions)) { // Okay, we extracted some blocks and the problem still appears. See if we // can eliminate some of the created functions from being candidates. From alenhar2 at cs.uiuc.edu Tue Aug 2 18:29:32 2005 From: alenhar2 at cs.uiuc.edu (Andrew Lenharth) Date: Tue, 2 Aug 2005 18:29:32 -0500 Subject: [llvm-commits] CVS: llvm-test/External/SPEC/CINT95/147.vortex/Makefile Message-ID: <200508022329.SAA15910@zion.cs.uiuc.edu> Changes in directory llvm-test/External/SPEC/CINT95/147.vortex: Makefile updated: 1.5 -> 1.6 --- Log message: including Makefile.spec95 at the bottom wipes out the flags. also, use a flag the benchmark cares about. Probably other archs want this too --- Diffs of the changes: (+5 -3) Makefile | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-) Index: llvm-test/External/SPEC/CINT95/147.vortex/Makefile diff -u llvm-test/External/SPEC/CINT95/147.vortex/Makefile:1.5 llvm-test/External/SPEC/CINT95/147.vortex/Makefile:1.6 --- llvm-test/External/SPEC/CINT95/147.vortex/Makefile:1.5 Mon Apr 4 15:07:11 2005 +++ llvm-test/External/SPEC/CINT95/147.vortex/Makefile Tue Aug 2 18:29:20 2005 @@ -6,13 +6,17 @@ LDFLAGS += -lm LIBS += -lm +include ../../Makefile.spec95 + +#a grep of the source seems to say that SPEC_CPU2000_LP64 isn't used at all + ifeq ($(ARCH),Sparc) ## SPEC portability note for vortex says to use this flag on 64-bit machines CPPFLAGS += -DSPEC_CPU2000_LP64 endif ifeq ($(ARCH),Alpha) ## SPEC portability note for vortex says to use this flag on 64-bit machines - CPPFLAGS += -DSPEC_CPU2000_LP64 + CPPFLAGS += -DSPEC_CPU2000_LP64 -D__RISC_64__ endif ifeq ($(ARCH),IA64) ## SPEC portability note for vortex says to use this flag on 64-bit machines @@ -24,5 +28,3 @@ else RUN_OPTIONS = vortex.in.little endif - -include ../../Makefile.spec95 From lattner at cs.uiuc.edu Tue Aug 2 18:29:35 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue, 2 Aug 2005 18:29:35 -0500 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Utils/SimplifyCFG.cpp Message-ID: <200508022329.SAA15917@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Utils: SimplifyCFG.cpp updated: 1.73 -> 1.74 --- Log message: Change a place to use an arbitrary value instead of null, when possible --- Diffs of the changes: (+3 -3) SimplifyCFG.cpp | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) Index: llvm/lib/Transforms/Utils/SimplifyCFG.cpp diff -u llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.73 llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.74 --- llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.73 Mon Aug 1 22:24:05 2005 +++ llvm/lib/Transforms/Utils/SimplifyCFG.cpp Tue Aug 2 18:29:23 2005 @@ -849,13 +849,13 @@ while (!BB->empty()) { Instruction &I = BB->back(); // If this instruction is used, replace uses with an arbitrary - // constant value. Because control flow can't get here, we don't care + // value. Because control flow can't get here, we don't care // what we replace the value with. Note that since this block is // unreachable, and all values contained within it must dominate their // uses, that all uses will eventually be removed. if (!I.use_empty()) - // Make all users of this instruction reference the constant instead - I.replaceAllUsesWith(Constant::getNullValue(I.getType())); + // Make all users of this instruction use undef instead + I.replaceAllUsesWith(UndefValue::get(I.getType())); // Remove the instruction from the basic block BB->getInstList().pop_back(); From lattner at cs.uiuc.edu Tue Aug 2 18:31:50 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue, 2 Aug 2005 18:31:50 -0500 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Utils/SimplifyCFG.cpp Message-ID: <200508022331.SAA15986@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Utils: SimplifyCFG.cpp updated: 1.74 -> 1.75 --- Log message: Disable this patch: http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20050801/027345.html This breaks real programs and only fixes an obscure regression testcase. A real fix is in development. --- Diffs of the changes: (+1 -1) SimplifyCFG.cpp | 2 +- 1 files changed, 1 insertion(+), 1 deletion(-) Index: llvm/lib/Transforms/Utils/SimplifyCFG.cpp diff -u llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.74 llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.75 --- llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.74 Tue Aug 2 18:29:23 2005 +++ llvm/lib/Transforms/Utils/SimplifyCFG.cpp Tue Aug 2 18:31:38 2005 @@ -894,7 +894,7 @@ // Move all PHI nodes in BB to Succ if they are alive, otherwise // delete them. while (PHINode *PN = dyn_cast(&BB->front())) - if (PN->use_empty() || Succ->getSinglePredecessor() == 0) { + if (PN->use_empty() /*|| Succ->getSinglePredecessor() == 0*/) { // We can only move the PHI node into Succ if BB dominates Succ. // Since BB only has a single successor (Succ), the PHI nodes // will dominate Succ, unless Succ has multiple predecessors. In From alenhar2 at cs.uiuc.edu Tue Aug 2 18:33:31 2005 From: alenhar2 at cs.uiuc.edu (Andrew Lenharth) Date: Tue, 2 Aug 2005 18:33:31 -0500 Subject: [llvm-commits] CVS: llvm-test/External/SPEC/CINT95/147.vortex/Makefile Message-ID: <200508022333.SAA16006@zion.cs.uiuc.edu> Changes in directory llvm-test/External/SPEC/CINT95/147.vortex: Makefile updated: 1.6 -> 1.7 --- Log message: so this is spec95 after all. Hope that other 64 bit platforms want the 64 bit flag set for them too --- Diffs of the changes: (+3 -5) Makefile | 8 +++----- 1 files changed, 3 insertions(+), 5 deletions(-) Index: llvm-test/External/SPEC/CINT95/147.vortex/Makefile diff -u llvm-test/External/SPEC/CINT95/147.vortex/Makefile:1.6 llvm-test/External/SPEC/CINT95/147.vortex/Makefile:1.7 --- llvm-test/External/SPEC/CINT95/147.vortex/Makefile:1.6 Tue Aug 2 18:29:20 2005 +++ llvm-test/External/SPEC/CINT95/147.vortex/Makefile Tue Aug 2 18:33:19 2005 @@ -8,19 +8,17 @@ include ../../Makefile.spec95 -#a grep of the source seems to say that SPEC_CPU2000_LP64 isn't used at all - ifeq ($(ARCH),Sparc) ## SPEC portability note for vortex says to use this flag on 64-bit machines - CPPFLAGS += -DSPEC_CPU2000_LP64 + CPPFLAGS += -D__RISC_64__ endif ifeq ($(ARCH),Alpha) ## SPEC portability note for vortex says to use this flag on 64-bit machines - CPPFLAGS += -DSPEC_CPU2000_LP64 -D__RISC_64__ + CPPFLAGS += -D__RISC_64__ endif ifeq ($(ARCH),IA64) ## SPEC portability note for vortex says to use this flag on 64-bit machines - CPPFLAGS += -DSPEC_CPU2000_LP64 + CPPFLAGS += -D__RISC_64__ endif ifeq ($(ENDIAN), big) From lattner at cs.uiuc.edu Tue Aug 2 19:10:39 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue, 2 Aug 2005 19:10:39 -0500 Subject: [llvm-commits] CVS: llvm/test/Regression/Transforms/SimplifyCFG/2005-08-01-PHIUpdateFail.ll Message-ID: <200508030010.TAA16922@zion.cs.uiuc.edu> Changes in directory llvm/test/Regression/Transforms/SimplifyCFG: 2005-08-01-PHIUpdateFail.ll updated: 1.1 -> 1.2 --- Log message: This fails for now --- Diffs of the changes: (+1 -0) 2005-08-01-PHIUpdateFail.ll | 1 + 1 files changed, 1 insertion(+) Index: llvm/test/Regression/Transforms/SimplifyCFG/2005-08-01-PHIUpdateFail.ll diff -u llvm/test/Regression/Transforms/SimplifyCFG/2005-08-01-PHIUpdateFail.ll:1.1 llvm/test/Regression/Transforms/SimplifyCFG/2005-08-01-PHIUpdateFail.ll:1.2 --- llvm/test/Regression/Transforms/SimplifyCFG/2005-08-01-PHIUpdateFail.ll:1.1 Mon Aug 1 22:23:03 2005 +++ llvm/test/Regression/Transforms/SimplifyCFG/2005-08-01-PHIUpdateFail.ll Tue Aug 2 19:10:28 2005 @@ -1,4 +1,5 @@ ; RUN: llvm-as < %s | opt -simplifycfg -disable-output +; XFAIL: * void %main() { entry: From lattner at cs.uiuc.edu Tue Aug 2 19:11:28 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue, 2 Aug 2005 19:11:28 -0500 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Utils/SimplifyCFG.cpp Message-ID: <200508030011.TAA16958@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Utils: SimplifyCFG.cpp updated: 1.75 -> 1.76 --- Log message: Rip some code out of the main SimplifyCFG function into a subfunction and call it from the only place it is live. No functionality changes. --- Diffs of the changes: (+72 -78) SimplifyCFG.cpp | 150 ++++++++++++++++++++++++++------------------------------ 1 files changed, 72 insertions(+), 78 deletions(-) Index: llvm/lib/Transforms/Utils/SimplifyCFG.cpp diff -u llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.75 llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.76 --- llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.75 Tue Aug 2 18:31:38 2005 +++ llvm/lib/Transforms/Utils/SimplifyCFG.cpp Tue Aug 2 19:11:16 2005 @@ -91,6 +91,66 @@ return false; } +/// TryToSimplifyUncondBranchFromEmptyBlock - BB contains an unconditional +/// branch to Succ, and contains no instructions other than PHI nodes and the +/// branch. If possible, eliminate BB. +static bool TryToSimplifyUncondBranchFromEmptyBlock(BasicBlock *BB, + BasicBlock *Succ) { + // If our successor has PHI nodes, then we need to update them to include + // entries for BB's predecessors, not for BB itself. Be careful though, + // if this transformation fails (returns true) then we cannot do this + // transformation! + // + if (PropagatePredecessorsForPHIs(BB, Succ)) return false; + + DEBUG(std::cerr << "Killing Trivial BB: \n" << *BB); + + if (isa(&BB->front())) { + std::vector + OldSuccPreds(pred_begin(Succ), pred_end(Succ)); + + // Move all PHI nodes in BB to Succ if they are alive, otherwise + // delete them. + while (PHINode *PN = dyn_cast(&BB->front())) + if (PN->use_empty() /*|| Succ->getSinglePredecessor() == 0*/) { + // We can only move the PHI node into Succ if BB dominates Succ. + // Since BB only has a single successor (Succ), the PHI nodes + // will dominate Succ, unless Succ has multiple predecessors. In + // this case, the PHIs are either dead, or have references in dead + // blocks. In either case, we can just remove them. + if (!PN->use_empty()) // Uses in dead block? + PN->replaceAllUsesWith(UndefValue::get(PN->getType())); + PN->eraseFromParent(); // Nuke instruction. + } else { + // The instruction is alive, so this means that Succ must have + // *ONLY* had BB as a predecessor, and the PHI node is still valid + // now. Simply move it into Succ, because we know that BB + // strictly dominated Succ. + BB->getInstList().remove(BB->begin()); + Succ->getInstList().push_front(PN); + + // We need to add new entries for the PHI node to account for + // predecessors of Succ that the PHI node does not take into + // account. At this point, since we know that BB dominated succ, + // this means that we should any newly added incoming edges should + // use the PHI node as the value for these edges, because they are + // loop back edges. + for (unsigned i = 0, e = OldSuccPreds.size(); i != e; ++i) + if (OldSuccPreds[i] != BB) + PN->addIncoming(PN, OldSuccPreds[i]); + } + } + + // Everything that jumped to BB now goes to Succ. + std::string OldName = BB->getName(); + BB->replaceAllUsesWith(Succ); + BB->eraseFromParent(); // Delete the old basic block. + + if (!OldName.empty() && !Succ->hasName()) // Transfer name if we can + Succ->setName(OldName); + return true; +} + /// GetIfCondition - Given a basic block (BB) with two predecessors (and /// presumably PHI nodes in it), check to see if the merge at this block is due /// to an "if condition". If so, return the boolean condition that determines @@ -820,7 +880,6 @@ }; } - // SimplifyCFG - This function is used to do simplification of a CFG. For // example, it adjusts branches to branches to eliminate the extra hop, it // eliminates unreachable basic blocks, and does other "peephole" optimization @@ -868,73 +927,6 @@ // away... Changed |= ConstantFoldTerminator(BB); - // Check to see if this block has no non-phi instructions and only a single - // successor. If so, replace references to this basic block with references - // to the successor. - succ_iterator SI(succ_begin(BB)); - if (SI != succ_end(BB) && ++SI == succ_end(BB)) { // One succ? - BasicBlock::iterator BBI = BB->begin(); // Skip over phi nodes... - while (isa(*BBI)) ++BBI; - - BasicBlock *Succ = *succ_begin(BB); // There is exactly one successor. - if (BBI->isTerminator() && // Terminator is the only non-phi instruction! - Succ != BB) { // Don't hurt infinite loops! - // If our successor has PHI nodes, then we need to update them to include - // entries for BB's predecessors, not for BB itself. Be careful though, - // if this transformation fails (returns true) then we cannot do this - // transformation! - // - if (!PropagatePredecessorsForPHIs(BB, Succ)) { - DEBUG(std::cerr << "Killing Trivial BB: \n" << *BB); - - if (isa(&BB->front())) { - std::vector - OldSuccPreds(pred_begin(Succ), pred_end(Succ)); - - // Move all PHI nodes in BB to Succ if they are alive, otherwise - // delete them. - while (PHINode *PN = dyn_cast(&BB->front())) - if (PN->use_empty() /*|| Succ->getSinglePredecessor() == 0*/) { - // We can only move the PHI node into Succ if BB dominates Succ. - // Since BB only has a single successor (Succ), the PHI nodes - // will dominate Succ, unless Succ has multiple predecessors. In - // this case, the PHIs are either dead, or have references in dead - // blocks. In either case, we can just remove them. - if (!PN->use_empty()) // Uses in dead block? - PN->replaceAllUsesWith(UndefValue::get(PN->getType())); - PN->eraseFromParent(); // Nuke instruction. - } else { - // The instruction is alive, so this means that Succ must have - // *ONLY* had BB as a predecessor, and the PHI node is still valid - // now. Simply move it into Succ, because we know that BB - // strictly dominated Succ. - BB->getInstList().remove(BB->begin()); - Succ->getInstList().push_front(PN); - - // We need to add new entries for the PHI node to account for - // predecessors of Succ that the PHI node does not take into - // account. At this point, since we know that BB dominated succ, - // this means that we should any newly added incoming edges should - // use the PHI node as the value for these edges, because they are - // loop back edges. - for (unsigned i = 0, e = OldSuccPreds.size(); i != e; ++i) - if (OldSuccPreds[i] != BB) - PN->addIncoming(PN, OldSuccPreds[i]); - } - } - - // Everything that jumped to BB now goes to Succ. - std::string OldName = BB->getName(); - BB->replaceAllUsesWith(Succ); - BB->eraseFromParent(); // Delete the old basic block. - - if (!OldName.empty() && !Succ->hasName()) // Transfer name if we can - Succ->setName(OldName); - return true; - } - } - } - // If this is a returning block with only PHI nodes in it, fold the return // instruction into any unconditional branch predecessors. // @@ -1105,7 +1097,17 @@ return SimplifyCFG(BB) || 1; } } else if (BranchInst *BI = dyn_cast(BB->getTerminator())) { - if (BI->isConditional()) { + if (BI->isUnconditional()) { + BasicBlock::iterator BBI = BB->begin(); // Skip over phi nodes... + while (isa(*BBI)) ++BBI; + + BasicBlock *Succ = BI->getSuccessor(0); + if (BBI->isTerminator() && // Terminator is the only non-phi instruction! + Succ != BB) // Don't hurt infinite loops! + if (TryToSimplifyUncondBranchFromEmptyBlock(BB, Succ)) + return 1; + + } else { // Conditional branch if (Value *CompVal = isValueEqualityComparison(BI)) { // If we only have one predecessor, and if it is a branch on this value, // see if that predecessor totally determines the outcome of this @@ -1180,15 +1182,7 @@ // If this block ends with a branch instruction, and if there is one // predecessor, see if the previous block ended with a branch on the same // condition, which makes this conditional branch redundant. - pred_iterator PI(pred_begin(BB)), PE(pred_end(BB)); - BasicBlock *OnlyPred = *PI++; - for (; PI != PE; ++PI)// Search all predecessors, see if they are all same - if (*PI != OnlyPred) { - OnlyPred = 0; // There are multiple different predecessors... - break; - } - - if (OnlyPred) + if (BasicBlock *OnlyPred = BB->getSinglePredecessor()) if (BranchInst *PBI = dyn_cast(OnlyPred->getTerminator())) if (PBI->isConditional() && PBI->getCondition() == BI->getCondition() && From lattner at cs.uiuc.edu Tue Aug 2 19:19:56 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue, 2 Aug 2005 19:19:56 -0500 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Utils/SimplifyCFG.cpp Message-ID: <200508030019.TAA17064@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Utils: SimplifyCFG.cpp updated: 1.76 -> 1.77 --- Log message: move two functions up in the file, use SafeToMergeTerminators to eliminate some duplicated code --- Diffs of the changes: (+45 -61) SimplifyCFG.cpp | 106 +++++++++++++++++++++++--------------------------------- 1 files changed, 45 insertions(+), 61 deletions(-) Index: llvm/lib/Transforms/Utils/SimplifyCFG.cpp diff -u llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.76 llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.77 --- llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.76 Tue Aug 2 19:11:16 2005 +++ llvm/lib/Transforms/Utils/SimplifyCFG.cpp Tue Aug 2 19:19:45 2005 @@ -24,6 +24,49 @@ #include using namespace llvm; +/// SafeToMergeTerminators - Return true if it is safe to merge these two +/// terminator instructions together. +/// +static bool SafeToMergeTerminators(TerminatorInst *SI1, TerminatorInst *SI2) { + if (SI1 == SI2) return false; // Can't merge with self! + + // It is not safe to merge these two switch instructions if they have a common + // successor, and if that successor has a PHI node, and if *that* PHI node has + // conflicting incoming values from the two switch blocks. + BasicBlock *SI1BB = SI1->getParent(); + BasicBlock *SI2BB = SI2->getParent(); + std::set SI1Succs(succ_begin(SI1BB), succ_end(SI1BB)); + + for (succ_iterator I = succ_begin(SI2BB), E = succ_end(SI2BB); I != E; ++I) + if (SI1Succs.count(*I)) + for (BasicBlock::iterator BBI = (*I)->begin(); + isa(BBI); ++BBI) { + PHINode *PN = cast(BBI); + if (PN->getIncomingValueForBlock(SI1BB) != + PN->getIncomingValueForBlock(SI2BB)) + return false; + } + + return true; +} + +/// AddPredecessorToBlock - Update PHI nodes in Succ to indicate that there will +/// now be entries in it from the 'NewPred' block. The values that will be +/// flowing into the PHI nodes will be the same as those coming in from +/// ExistPred, an existing predecessor of Succ. +static void AddPredecessorToBlock(BasicBlock *Succ, BasicBlock *NewPred, + BasicBlock *ExistPred) { + assert(std::find(succ_begin(ExistPred), succ_end(ExistPred), Succ) != + succ_end(ExistPred) && "ExistPred is not a predecessor of Succ!"); + if (!isa(Succ->begin())) return; // Quick exit if nothing to do + + for (BasicBlock::iterator I = Succ->begin(); isa(I); ++I) { + PHINode *PN = cast(I); + Value *V = PN->getIncomingValueForBlock(ExistPred); + PN->addIncoming(V, NewPred); + } +} + // PropagatePredecessorsForPHIs - This gets "Succ" ready to have the // predecessors from "BB". This is a little tricky because "Succ" has PHI // nodes, which need to have extra slots added to them to hold the merge edges @@ -48,24 +91,8 @@ // Succ. If so, we cannot do the transformation if there are any PHI nodes // with incompatible values coming in from the two edges! // - for (pred_iterator PI = pred_begin(Succ), PE = pred_end(Succ); PI != PE; ++PI) - if (std::find(BBPreds.begin(), BBPreds.end(), *PI) != BBPreds.end()) { - // Loop over all of the PHI nodes checking to see if there are - // incompatible values coming in. - for (BasicBlock::iterator I = Succ->begin(); isa(I); ++I) { - PHINode *PN = cast(I); - // Loop up the entries in the PHI node for BB and for *PI if the values - // coming in are non-equal, we cannot merge these two blocks (instead we - // should insert a conditional move or something, then merge the - // blocks). - int Idx1 = PN->getBasicBlockIndex(BB); - int Idx2 = PN->getBasicBlockIndex(*PI); - assert(Idx1 != -1 && Idx2 != -1 && - "Didn't have entries for my predecessors??"); - if (PN->getIncomingValue(Idx1) != PN->getIncomingValue(Idx2)) - return true; // Values are not equal... - } - } + if (!SafeToMergeTerminators(BB->getTerminator(), Succ->getTerminator())) + return true; // Cannot merge. // Loop over all of the PHI nodes in the successor BB. for (BasicBlock::iterator I = Succ->begin(); isa(I); ++I) { @@ -398,49 +425,6 @@ } } -/// SafeToMergeTerminators - Return true if it is safe to merge these two -/// terminator instructions together. -/// -static bool SafeToMergeTerminators(TerminatorInst *SI1, TerminatorInst *SI2) { - if (SI1 == SI2) return false; // Can't merge with self! - - // It is not safe to merge these two switch instructions if they have a common - // successor, and if that successor has a PHI node, and if *that* PHI node has - // conflicting incoming values from the two switch blocks. - BasicBlock *SI1BB = SI1->getParent(); - BasicBlock *SI2BB = SI2->getParent(); - std::set SI1Succs(succ_begin(SI1BB), succ_end(SI1BB)); - - for (succ_iterator I = succ_begin(SI2BB), E = succ_end(SI2BB); I != E; ++I) - if (SI1Succs.count(*I)) - for (BasicBlock::iterator BBI = (*I)->begin(); - isa(BBI); ++BBI) { - PHINode *PN = cast(BBI); - if (PN->getIncomingValueForBlock(SI1BB) != - PN->getIncomingValueForBlock(SI2BB)) - return false; - } - - return true; -} - -/// AddPredecessorToBlock - Update PHI nodes in Succ to indicate that there will -/// now be entries in it from the 'NewPred' block. The values that will be -/// flowing into the PHI nodes will be the same as those coming in from -/// ExistPred, an existing predecessor of Succ. -static void AddPredecessorToBlock(BasicBlock *Succ, BasicBlock *NewPred, - BasicBlock *ExistPred) { - assert(std::find(succ_begin(ExistPred), succ_end(ExistPred), Succ) != - succ_end(ExistPred) && "ExistPred is not a predecessor of Succ!"); - if (!isa(Succ->begin())) return; // Quick exit if nothing to do - - for (BasicBlock::iterator I = Succ->begin(); isa(I); ++I) { - PHINode *PN = cast(I); - Value *V = PN->getIncomingValueForBlock(ExistPred); - PN->addIncoming(V, NewPred); - } -} - // isValueEqualityComparison - Return true if the specified terminator checks to // see if a value is equal to constant integer value. static Value *isValueEqualityComparison(TerminatorInst *TI) { From lattner at cs.uiuc.edu Tue Aug 2 19:23:53 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue, 2 Aug 2005 19:23:53 -0500 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Utils/SimplifyCFG.cpp Message-ID: <200508030023.TAA17133@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Utils: SimplifyCFG.cpp updated: 1.77 -> 1.78 --- Log message: use splice instead of remove/insert to avoid some symtab operations --- Diffs of the changes: (+2 -2) SimplifyCFG.cpp | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) Index: llvm/lib/Transforms/Utils/SimplifyCFG.cpp diff -u llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.77 llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.78 --- llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.77 Tue Aug 2 19:19:45 2005 +++ llvm/lib/Transforms/Utils/SimplifyCFG.cpp Tue Aug 2 19:23:42 2005 @@ -153,8 +153,8 @@ // *ONLY* had BB as a predecessor, and the PHI node is still valid // now. Simply move it into Succ, because we know that BB // strictly dominated Succ. - BB->getInstList().remove(BB->begin()); - Succ->getInstList().push_front(PN); + Succ->getInstList().splice(Succ->begin(), + BB->getInstList(), BB->begin()); // We need to add new entries for the PHI node to account for // predecessors of Succ that the PHI node does not take into From lattner at cs.uiuc.edu Tue Aug 2 19:29:37 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue, 2 Aug 2005 19:29:37 -0500 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Utils/SimplifyCFG.cpp Message-ID: <200508030029.TAA17209@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Utils: SimplifyCFG.cpp updated: 1.78 -> 1.79 --- Log message: Refactor code out of PropagatePredecessorsForPHIs, turning it into a pure function with no side-effects --- Diffs of the changes: (+36 -37) SimplifyCFG.cpp | 73 +++++++++++++++++++++++++++----------------------------- 1 files changed, 36 insertions(+), 37 deletions(-) Index: llvm/lib/Transforms/Utils/SimplifyCFG.cpp diff -u llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.78 llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.79 --- llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.78 Tue Aug 2 19:23:42 2005 +++ llvm/lib/Transforms/Utils/SimplifyCFG.cpp Tue Aug 2 19:29:26 2005 @@ -67,55 +67,25 @@ } } -// PropagatePredecessorsForPHIs - This gets "Succ" ready to have the -// predecessors from "BB". This is a little tricky because "Succ" has PHI -// nodes, which need to have extra slots added to them to hold the merge edges -// from BB's predecessors, and BB itself might have had PHI nodes in it. This -// function returns true (failure) if the Succ BB already has a predecessor that -// is a predecessor of BB and incoming PHI arguments would not be discernible. +// CanPropagatePredecessorsForPHIs - Return true if we can fold BB, an +// almost-empty BB ending in an unconditional branch to Succ, into succ. // // Assumption: Succ is the single successor for BB. // -static bool PropagatePredecessorsForPHIs(BasicBlock *BB, BasicBlock *Succ) { +static bool CanPropagatePredecessorsForPHIs(BasicBlock *BB, BasicBlock *Succ) { assert(*succ_begin(BB) == Succ && "Succ is not successor of BB!"); if (!isa(Succ->front())) - return false; // We can make the transformation, no problem. - - // If there is more than one predecessor, and there are PHI nodes in - // the successor, then we need to add incoming edges for the PHI nodes - // - const std::vector BBPreds(pred_begin(BB), pred_end(BB)); + return true; // We can make the transformation, no problem. // Check to see if one of the predecessors of BB is already a predecessor of // Succ. If so, we cannot do the transformation if there are any PHI nodes // with incompatible values coming in from the two edges! // if (!SafeToMergeTerminators(BB->getTerminator(), Succ->getTerminator())) - return true; // Cannot merge. + return false; // Cannot merge. - // Loop over all of the PHI nodes in the successor BB. - for (BasicBlock::iterator I = Succ->begin(); isa(I); ++I) { - PHINode *PN = cast(I); - Value *OldVal = PN->removeIncomingValue(BB, false); - assert(OldVal && "No entry in PHI for Pred BB!"); - - // If this incoming value is one of the PHI nodes in BB, the new entries in - // the PHI node are the entries from the old PHI. - if (isa(OldVal) && cast(OldVal)->getParent() == BB) { - PHINode *OldValPN = cast(OldVal); - for (unsigned i = 0, e = OldValPN->getNumIncomingValues(); i != e; ++i) - PN->addIncoming(OldValPN->getIncomingValue(i), - OldValPN->getIncomingBlock(i)); - } else { - for (std::vector::const_iterator PredI = BBPreds.begin(), - End = BBPreds.end(); PredI != End; ++PredI) { - // Add an incoming value for each of the new incoming values... - PN->addIncoming(OldVal, *PredI); - } - } - } - return false; + return true; } /// TryToSimplifyUncondBranchFromEmptyBlock - BB contains an unconditional @@ -128,10 +98,39 @@ // if this transformation fails (returns true) then we cannot do this // transformation! // - if (PropagatePredecessorsForPHIs(BB, Succ)) return false; + if (!CanPropagatePredecessorsForPHIs(BB, Succ)) return false; DEBUG(std::cerr << "Killing Trivial BB: \n" << *BB); + if (isa(Succ->begin())) { + // If there is more than one pred of succ, and there are PHI nodes in + // the successor, then we need to add incoming edges for the PHI nodes + // + const std::vector BBPreds(pred_begin(BB), pred_end(BB)); + + // Loop over all of the PHI nodes in the successor of BB. + for (BasicBlock::iterator I = Succ->begin(); isa(I); ++I) { + PHINode *PN = cast(I); + Value *OldVal = PN->removeIncomingValue(BB, false); + assert(OldVal && "No entry in PHI for Pred BB!"); + + // If this incoming value is one of the PHI nodes in BB, the new entries in + // the PHI node are the entries from the old PHI. + if (isa(OldVal) && cast(OldVal)->getParent() == BB) { + PHINode *OldValPN = cast(OldVal); + for (unsigned i = 0, e = OldValPN->getNumIncomingValues(); i != e; ++i) + PN->addIncoming(OldValPN->getIncomingValue(i), + OldValPN->getIncomingBlock(i)); + } else { + for (std::vector::const_iterator PredI = BBPreds.begin(), + End = BBPreds.end(); PredI != End; ++PredI) { + // Add an incoming value for each of the new incoming values... + PN->addIncoming(OldVal, *PredI); + } + } + } + } + if (isa(&BB->front())) { std::vector OldSuccPreds(pred_begin(Succ), pred_end(Succ)); From lattner at cs.uiuc.edu Tue Aug 2 19:38:38 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue, 2 Aug 2005 19:38:38 -0500 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Utils/SimplifyCFG.cpp Message-ID: <200508030038.TAA17284@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Utils: SimplifyCFG.cpp updated: 1.79 -> 1.80 --- Log message: Simplify some code, add the correct pred checks --- Diffs of the changes: (+25 -16) SimplifyCFG.cpp | 41 +++++++++++++++++++++++++---------------- 1 files changed, 25 insertions(+), 16 deletions(-) Index: llvm/lib/Transforms/Utils/SimplifyCFG.cpp diff -u llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.79 llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.80 --- llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.79 Tue Aug 2 19:29:26 2005 +++ llvm/lib/Transforms/Utils/SimplifyCFG.cpp Tue Aug 2 19:38:27 2005 @@ -75,15 +75,29 @@ static bool CanPropagatePredecessorsForPHIs(BasicBlock *BB, BasicBlock *Succ) { assert(*succ_begin(BB) == Succ && "Succ is not successor of BB!"); - if (!isa(Succ->front())) - return true; // We can make the transformation, no problem. - // Check to see if one of the predecessors of BB is already a predecessor of // Succ. If so, we cannot do the transformation if there are any PHI nodes // with incompatible values coming in from the two edges! // - if (!SafeToMergeTerminators(BB->getTerminator(), Succ->getTerminator())) - return false; // Cannot merge. + if (isa(Succ->front())) { + std::set BBPreds(pred_begin(BB), pred_end(BB)); + for (pred_iterator PI = pred_begin(Succ), PE = pred_end(Succ);\ + PI != PE; ++PI) + if (std::find(BBPreds.begin(), BBPreds.end(), *PI) != BBPreds.end()) { + // Loop over all of the PHI nodes checking to see if there are + // incompatible values coming in. + for (BasicBlock::iterator I = Succ->begin(); isa(I); ++I) { + PHINode *PN = cast(I); + // Loop up the entries in the PHI node for BB and for *PI if the + // values coming in are non-equal, we cannot merge these two blocks + // (instead we should insert a conditional move or something, then + // merge the blocks). + if (PN->getIncomingValueForBlock(BB) != + PN->getIncomingValueForBlock(*PI)) + return false; // Values are not equal... + } + } + } return true; } @@ -114,8 +128,8 @@ Value *OldVal = PN->removeIncomingValue(BB, false); assert(OldVal && "No entry in PHI for Pred BB!"); - // If this incoming value is one of the PHI nodes in BB, the new entries in - // the PHI node are the entries from the old PHI. + // If this incoming value is one of the PHI nodes in BB, the new entries + // in the PHI node are the entries from the old PHI. if (isa(OldVal) && cast(OldVal)->getParent() == BB) { PHINode *OldValPN = cast(OldVal); for (unsigned i = 0, e = OldValPN->getNumIncomingValues(); i != e; ++i) @@ -138,15 +152,10 @@ // Move all PHI nodes in BB to Succ if they are alive, otherwise // delete them. while (PHINode *PN = dyn_cast(&BB->front())) - if (PN->use_empty() /*|| Succ->getSinglePredecessor() == 0*/) { - // We can only move the PHI node into Succ if BB dominates Succ. - // Since BB only has a single successor (Succ), the PHI nodes - // will dominate Succ, unless Succ has multiple predecessors. In - // this case, the PHIs are either dead, or have references in dead - // blocks. In either case, we can just remove them. - if (!PN->use_empty()) // Uses in dead block? - PN->replaceAllUsesWith(UndefValue::get(PN->getType())); - PN->eraseFromParent(); // Nuke instruction. + if (PN->use_empty()) { + // Just remove the dead phi. This happens if Succ's PHIs were the only + // users of the PHI nodes. + PN->eraseFromParent(); } else { // The instruction is alive, so this means that Succ must have // *ONLY* had BB as a predecessor, and the PHI node is still valid From lattner at cs.uiuc.edu Tue Aug 2 19:58:55 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue, 2 Aug 2005 19:58:55 -0500 Subject: [llvm-commits] CVS: llvm/test/Regression/Transforms/SimplifyCFG/2005-08-01-PHIUpdateFail.ll Message-ID: <200508030058.TAA17467@zion.cs.uiuc.edu> Changes in directory llvm/test/Regression/Transforms/SimplifyCFG: 2005-08-01-PHIUpdateFail.ll updated: 1.2 -> 1.3 --- Log message: un-xfail this --- Diffs of the changes: (+0 -1) 2005-08-01-PHIUpdateFail.ll | 1 - 1 files changed, 1 deletion(-) Index: llvm/test/Regression/Transforms/SimplifyCFG/2005-08-01-PHIUpdateFail.ll diff -u llvm/test/Regression/Transforms/SimplifyCFG/2005-08-01-PHIUpdateFail.ll:1.2 llvm/test/Regression/Transforms/SimplifyCFG/2005-08-01-PHIUpdateFail.ll:1.3 --- llvm/test/Regression/Transforms/SimplifyCFG/2005-08-01-PHIUpdateFail.ll:1.2 Tue Aug 2 19:10:28 2005 +++ llvm/test/Regression/Transforms/SimplifyCFG/2005-08-01-PHIUpdateFail.ll Tue Aug 2 19:58:44 2005 @@ -1,5 +1,4 @@ ; RUN: llvm-as < %s | opt -simplifycfg -disable-output -; XFAIL: * void %main() { entry: From lattner at cs.uiuc.edu Tue Aug 2 19:59:23 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue, 2 Aug 2005 19:59:23 -0500 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Utils/SimplifyCFG.cpp Message-ID: <200508030059.TAA17477@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Utils: SimplifyCFG.cpp updated: 1.80 -> 1.81 --- Log message: Finally, add the required constraint checks to fix Transforms/SimplifyCFG/2005-08-01-PHIUpdateFail.ll the right way --- Diffs of the changes: (+29 -2) SimplifyCFG.cpp | 31 +++++++++++++++++++++++++++++-- 1 files changed, 29 insertions(+), 2 deletions(-) Index: llvm/lib/Transforms/Utils/SimplifyCFG.cpp diff -u llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.80 llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.81 --- llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.80 Tue Aug 2 19:38:27 2005 +++ llvm/lib/Transforms/Utils/SimplifyCFG.cpp Tue Aug 2 19:59:12 2005 @@ -98,8 +98,35 @@ } } } - - return true; + + // Finally, if BB has PHI nodes that are used by things other than the PHIs in + // Succ and Succ has predecessors that are not Succ and not Pred, we cannot + // fold these blocks, as we don't know whether BB dominates Succ or not to + // update the PHI nodes correctly. + if (!isa(BB->begin()) || Succ->getSinglePredecessor()) return true; + + // If the predecessors of Succ are only BB and Succ itself, we can handle this. + bool IsSafe = true; + for (pred_iterator PI = pred_begin(Succ), E = pred_end(Succ); PI != E; ++PI) + if (*PI != Succ && *PI != BB) { + IsSafe = false; + break; + } + if (IsSafe) return true; + + // If the PHI nodes in BB are only used by instructions in Succ, we are ok. + IsSafe = true; + for (BasicBlock::iterator I = BB->begin(); isa(I) && IsSafe; ++I) { + PHINode *PN = cast(I); + for (Value::use_iterator UI = PN->use_begin(), E = PN->use_end(); UI != E; + ++UI) + if (cast(*UI)->getParent() != Succ) { + IsSafe = false; + break; + } + } + + return IsSafe; } /// TryToSimplifyUncondBranchFromEmptyBlock - BB contains an unconditional From alenhar2 at cs.uiuc.edu Tue Aug 2 20:02:42 2005 From: alenhar2 at cs.uiuc.edu (Andrew Lenharth) Date: Tue, 02 Aug 2005 20:02:42 -0500 Subject: [llvm-commits] Re: llvm-commits Digest, Vol 14, Issue 4 In-Reply-To: <200508030011.j730BZ8R005473@dcs-maillist.cs.uiuc.edu> References: <200508030011.j730BZ8R005473@dcs-maillist.cs.uiuc.edu> Message-ID: <1123030963.23243.1.camel@localhost.localdomain> > Diffs of the changes: (+9 -0) > > RunSafely.sh | 9 +++++++++ > 1 files changed, 9 insertions(+) > > > Index: llvm-test/RunSafely.sh > diff -u llvm-test/RunSafely.sh:1.18 llvm-test/RunSafely.sh:1.19 > --- llvm-test/RunSafely.sh:1.18 Thu Jul 28 12:02:07 2005 > +++ llvm-test/RunSafely.sh Tue Aug 2 17:04:00 2005 > @@ -23,6 +23,15 @@ > case $SYSTEM in > CYGWIN*) > ;; > + Darwin*) > + # Disable core file emission, the script doesn't find it anyway because it is put > + # into /cores. > + ulimit -c 0 > + ulimit -t $ULIMIT > + # To prevent infinite loops which fill up the disk, specify a limit on size of > + # files being output by the tests. 10 MB should be enough for anybody. ;) Except for cores from lli. 10 MB < 18 MB (16 code 1 Global 1 constant) > + ulimit -f 10485760 > + ;; > *) > ulimit -t $ULIMIT > ulimit -c unlimited -- Andrew Lenharth -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part Url : http://lists.cs.uiuc.edu/pipermail/llvm-commits/attachments/20050802/32bdb1ca/attachment.bin From lattner at cs.uiuc.edu Tue Aug 2 20:04:51 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue, 2 Aug 2005 20:04:51 -0500 Subject: [llvm-commits] CVS: llvm/include/llvm/Support/MathExtras.h Message-ID: <200508030104.UAA17579@zion.cs.uiuc.edu> Changes in directory llvm/include/llvm/Support: MathExtras.h updated: 1.20 -> 1.21 --- Log message: Fix another bug in the clz patch that caused miscompilations when !gcc4 --- Diffs of the changes: (+2 -2) MathExtras.h | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) Index: llvm/include/llvm/Support/MathExtras.h diff -u llvm/include/llvm/Support/MathExtras.h:1.20 llvm/include/llvm/Support/MathExtras.h:1.21 --- llvm/include/llvm/Support/MathExtras.h:1.20 Tue Aug 2 15:21:33 2005 +++ llvm/include/llvm/Support/MathExtras.h Tue Aug 2 20:04:40 2005 @@ -142,12 +142,12 @@ // if some bits in hi portion if (Hi) { // leading zeros in hi portion plus all bits in lo portion - Count = CountLeadingZeros_32(Hi) + 32; + Count = CountLeadingZeros_32(Hi); } else { // get lo portion unsigned Lo = Lo_32(Value); // same as 32 bit value - Count = CountLeadingZeros_32(Lo); + Count = CountLeadingZeros_32(Lo)+32; } } #endif From sabre at nondot.org Tue Aug 2 20:05:24 2005 From: sabre at nondot.org (Chris Lattner) Date: Tue, 2 Aug 2005 20:05:24 -0500 (CDT) Subject: [llvm-commits] Re: llvm-commits Digest, Vol 14, Issue 4 In-Reply-To: <1123030963.23243.1.camel@localhost.localdomain> References: <200508030011.j730BZ8R005473@dcs-maillist.cs.uiuc.edu> <1123030963.23243.1.camel@localhost.localdomain> Message-ID: On Tue, 2 Aug 2005, Andrew Lenharth wrote: >> + ulimit -t $ULIMIT >> + # To prevent infinite loops which fill up the disk, specify a limit on size of >> + # files being output by the tests. 10 MB should be enough for anybody. ;) > > Except for cores from lli. 10 MB < 18 MB (16 code 1 Global 1 constant) The 10M limit is on output files from the process, not core files. -Chris -- http://nondot.org/sabre/ http://llvm.org/ From alenhar2 at cs.uiuc.edu Tue Aug 2 20:08:45 2005 From: alenhar2 at cs.uiuc.edu (Andrew Lenharth) Date: Tue, 02 Aug 2005 20:08:45 -0500 Subject: [llvm-commits] Re: llvm-commits Digest, Vol 14, Issue 4 In-Reply-To: References: <200508030011.j730BZ8R005473@dcs-maillist.cs.uiuc.edu> <1123030963.23243.1.camel@localhost.localdomain> Message-ID: <1123031325.23320.0.camel@localhost.localdomain> On Tue, 2005-08-02 at 20:05 -0500, Chris Lattner wrote: > On Tue, 2 Aug 2005, Andrew Lenharth wrote: > >> + ulimit -t $ULIMIT > >> + # To prevent infinite loops which fill up the disk, specify a limit on size of > >> + # files being output by the tests. 10 MB should be enough for anybody. ;) > > > > Except for cores from lli. 10 MB < 18 MB (16 code 1 Global 1 constant) > > The 10M limit is on output files from the process, not core files. That's too bad. It is easy to run out of disk space from lli core files too. Not that I might have experienced that... -- Andrew Lenharth -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part Url : http://lists.cs.uiuc.edu/pipermail/llvm-commits/attachments/20050802/569b860d/attachment.bin From sabre at nondot.org Wed Aug 3 11:45:37 2005 From: sabre at nondot.org (Chris Lattner) Date: Wed, 3 Aug 2005 11:45:37 -0500 (CDT) Subject: [llvm-commits] Re: llvm-commits Digest, Vol 14, Issue 4 In-Reply-To: <1123031325.23320.0.camel@localhost.localdomain> References: <200508030011.j730BZ8R005473@dcs-maillist.cs.uiuc.edu> <1123030963.23243.1.camel@localhost.localdomain> <1123031325.23320.0.camel@localhost.localdomain> Message-ID: On Tue, 2 Aug 2005, Andrew Lenharth wrote: >>> Except for cores from lli. 10 MB < 18 MB (16 code 1 Global 1 constant) >> >> The 10M limit is on output files from the process, not core files. > > That's too bad. It is easy to run out of disk space from lli core files > too. Not that I might have experienced that... RunSafely removes them after it prints the stack trace. Assuming, of course, that the core files go in the current directory. This is not the case for darwin, so I disabled it. -Chris -- http://nondot.org/sabre/ http://llvm.org/ From lattner at cs.uiuc.edu Wed Aug 3 11:52:33 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Wed, 3 Aug 2005 11:52:33 -0500 Subject: [llvm-commits] CVS: llvm/lib/Target/PowerPC/PPC32ISelPattern.cpp Message-ID: <200508031652.LAA19078@zion.cs.uiuc.edu> Changes in directory llvm/lib/Target/PowerPC: PPC32ISelPattern.cpp updated: 1.112 -> 1.113 --- Log message: minor capitalization thing, patch by Jim Laskey --- Diffs of the changes: (+1 -1) PPC32ISelPattern.cpp | 2 +- 1 files changed, 1 insertion(+), 1 deletion(-) Index: llvm/lib/Target/PowerPC/PPC32ISelPattern.cpp diff -u llvm/lib/Target/PowerPC/PPC32ISelPattern.cpp:1.112 llvm/lib/Target/PowerPC/PPC32ISelPattern.cpp:1.113 --- llvm/lib/Target/PowerPC/PPC32ISelPattern.cpp:1.112 Tue Aug 2 14:30:55 2005 +++ llvm/lib/Target/PowerPC/PPC32ISelPattern.cpp Wed Aug 3 11:52:22 2005 @@ -36,7 +36,7 @@ using namespace llvm; -// IsRunOfOnes - returns true if Val consists of one contiguous run of 1's with +// IsRunOfOnes - Returns true if Val consists of one contiguous run of 1's with // any number of 0's on either side. the 1's are allowed to wrap from LSB to // MSB. so 0x000FFF0, 0x0000FFFF, and 0xFF0000FF are all runs. 0x0F0F0000 is // not, since all 1's are not contiguous. From lattner at cs.uiuc.edu Wed Aug 3 11:54:09 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Wed, 3 Aug 2005 11:54:09 -0500 Subject: [llvm-commits] CVS: llvm/include/llvm/Support/MathExtras.h Message-ID: <200508031654.LAA19136@zion.cs.uiuc.edu> Changes in directory llvm/include/llvm/Support: MathExtras.h updated: 1.21 -> 1.22 --- Log message: Wrap comments to 80 cols, fix code sequence for CountLeadingZeros_64 on non-ppc GCC 4.0 machines. Patch by Jim Laskey! --- Diffs of the changes: (+20 -19) MathExtras.h | 39 ++++++++++++++++++++------------------- 1 files changed, 20 insertions(+), 19 deletions(-) Index: llvm/include/llvm/Support/MathExtras.h diff -u llvm/include/llvm/Support/MathExtras.h:1.21 llvm/include/llvm/Support/MathExtras.h:1.22 --- llvm/include/llvm/Support/MathExtras.h:1.21 Tue Aug 2 20:04:40 2005 +++ llvm/include/llvm/Support/MathExtras.h Wed Aug 3 11:53:58 2005 @@ -18,8 +18,9 @@ namespace llvm { -// NOTE: The following support functions use the _32/_64 extensions instead of type -// overloading so that signed and unsigned integers can be used without ambiguity. +// NOTE: The following support functions use the _32/_64 extensions instead of +// type overloading so that signed and unsigned integers can be used without +// ambiguity. // Hi_32 - This function returns the high 32 bits of a 64 bit value. @@ -40,34 +41,34 @@ inline bool isInt32 (int64_t Value) { return ( signed int )Value == Value; } inline bool isUInt32(int64_t Value) { return (unsigned int )Value == Value; } -// isMask_32 - This function returns true if the argument is a sequence of ones starting -// at the least significant bit with the remainder zero (32 bit version.) +// isMask_32 - This function returns true if the argument is a sequence of ones +// starting at the least significant bit with the remainder zero (32 bit version.) // Ex. isMask_32(0x0000FFFFU) == true. inline const bool isMask_32(unsigned Value) { return Value && ((Value + 1) & Value) == 0; } -// isMask_64 - This function returns true if the argument is a sequence of ones starting -// at the least significant bit with the remainder zero (64 bit version.) +// isMask_64 - This function returns true if the argument is a sequence of ones +// starting at the least significant bit with the remainder zero (64 bit version.) inline const bool isMask_64(uint64_t Value) { return Value && ((Value + 1) & Value) == 0; } -// isShiftedMask_32 - This function returns true if the argument contains a sequence of ones -// with the remainder zero (32 bit version.) +// isShiftedMask_32 - This function returns true if the argument contains a +// sequence of ones with the remainder zero (32 bit version.) // Ex. isShiftedMask_32(0x0000FF00U) == true. inline const bool isShiftedMask_32(unsigned Value) { return isMask_32((Value - 1) | Value); } -// isShiftedMask_64 - This function returns true if the argument contains a sequence of ones -// with the remainder zero (64 bit version.) +// isShiftedMask_64 - This function returns true if the argument contains a +// sequence of ones with the remainder zero (64 bit version.) inline const bool isShiftedMask_64(uint64_t Value) { return isMask_64((Value - 1) | Value); } -// isPowerOf2_32 - This function returns true if the argument is a power of two > 0. -// Ex. isPowerOf2_32(0x00100000U) == true (32 bit edition.) +// isPowerOf2_32 - This function returns true if the argument is a power of +// two > 0. Ex. isPowerOf2_32(0x00100000U) == true (32 bit edition.) inline bool isPowerOf2_32(unsigned Value) { return Value && !(Value & (Value - 1)); } @@ -111,14 +112,14 @@ } // CountLeadingZeros_64 - This function performs the platform optimal form -// of counting the number of zeros from the most significant bit to the first one bit -// (64 bit edition.) +// of counting the number of zeros from the most significant bit to the first +// one bit (64 bit edition.) // Returns 64 if the word is zero. inline unsigned CountLeadingZeros_64(uint64_t Value) { unsigned Count; // result #if __GNUC__ >= 4 // PowerPC is defined for __builtin_clzll(0) -#if defined(__ppc__) || defined(__ppc64__) +#if !defined(__ppc__) && !defined(__ppc64__) if (!Value) return 64; #endif Count = __builtin_clzll(Value); @@ -154,15 +155,15 @@ return Count; } -// Log2_32 - This function returns the floor log base 2 of the specified value, -1 if the value is zero. -// (32 bit edition.) +// Log2_32 - This function returns the floor log base 2 of the specified value, +// -1 if the value is zero. (32 bit edition.) // Ex. Log2_32(32) == 5, Log2_32(1) == 0, Log2_32(0) == -1 inline unsigned Log2_32(unsigned Value) { return 31 - CountLeadingZeros_32(Value); } -// Log2_64 - This function returns the floor log base 2 of the specified value, -1 if the value is zero. -// (64 bit edition.) +// Log2_64 - This function returns the floor log base 2 of the specified value, +// -1 if the value is zero. (64 bit edition.) inline unsigned Log2_64(unsigned Value) { return 63 - CountLeadingZeros_64(Value); } From lattner at cs.uiuc.edu Tue Aug 2 14:25:17 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue, 2 Aug 2005 14:25:17 -0500 Subject: [llvm-commits] CVS: llvm/lib/Target/PowerPC/PPC32ISelPattern.cpp PPC32ISelSimple.cpp PPC64ISelPattern.cpp PowerPCAsmPrinter.cpp Message-ID: <200508021925.OAA07690@zion.cs.uiuc.edu> Changes in directory llvm/lib/Target/PowerPC: PPC32ISelPattern.cpp updated: 1.110 -> 1.111 PPC32ISelSimple.cpp updated: 1.143 -> 1.144 PPC64ISelPattern.cpp updated: 1.26 -> 1.27 PowerPCAsmPrinter.cpp updated: 1.83 -> 1.84 --- Log message: Update to use the new MathExtras.h support for log2 computation. Patch contributed by Jim Laskey! --- Diffs of the changes: (+78 -106) PPC32ISelPattern.cpp | 46 ++++++++++++++++----- PPC32ISelSimple.cpp | 105 +++++++++++++++----------------------------------- PPC64ISelPattern.cpp | 31 ++++---------- PowerPCAsmPrinter.cpp | 2 4 files changed, 78 insertions(+), 106 deletions(-) Index: llvm/lib/Target/PowerPC/PPC32ISelPattern.cpp diff -u llvm/lib/Target/PowerPC/PPC32ISelPattern.cpp:1.110 llvm/lib/Target/PowerPC/PPC32ISelPattern.cpp:1.111 --- llvm/lib/Target/PowerPC/PPC32ISelPattern.cpp:1.110 Tue Aug 2 14:07:49 2005 +++ llvm/lib/Target/PowerPC/PPC32ISelPattern.cpp Tue Aug 2 14:25:03 2005 @@ -35,6 +35,29 @@ #include using namespace llvm; + +// IsRunOfOnes - returns true if Val consists of one contiguous run of 1's with +// any number of 0's on either side. the 1's are allowed to wrap from LSB to +// MSB. so 0x000FFF0, 0x0000FFFF, and 0xFF0000FF are all runs. 0x0F0F0000 is +// not, since all 1's are not contiguous. +static bool IsRunOfOnes(unsigned Val, unsigned &MB, unsigned &ME) { + if (isShiftedMask_32(Val)) { + // look for the first non-zero bit + MB = CountLeadingZeros_32(Val); + // look for the first zero bit after the run of ones + ME = CountLeadingZeros_32((Val - 1) ^ Val); + return true; + } else if (isShiftedMask_32(Val = ~Val)) { // invert mask + // effectively look for the first zero bit + ME = CountLeadingZeros_32(Val) - 1; + // effectively look for the first one bit after the run of zeros + MB = CountLeadingZeros_32((Val - 1) ^ Val) + 1; + return true; + } + // no run present + return false; +} + //===----------------------------------------------------------------------===// // PPC32TargetLowering - PPC32 Implementation of the TargetLowering interface namespace { @@ -321,6 +344,7 @@ // Just to be safe, we'll always reserve the full 24 bytes of linkage area // plus 32 bytes of argument space in case any called code gets funky on us. + // (Required by ABI to support var arg) if (NumBytes < 56) NumBytes = 56; // Adjust the stack pointer for the new arguments... @@ -664,36 +688,36 @@ switch(Opcode) { default: return 0; case ISD::ADD: - if (v <= 32767 && v >= -32768) { Imm = v & 0xFFFF; return 1; } + if (isInt16(v)) { Imm = v & 0xFFFF; return 1; } if ((v & 0x0000FFFF) == 0) { Imm = v >> 16; return 2; } break; case ISD::AND: { unsigned MB, ME; if (IsRunOfOnes(v, MB, ME)) { Imm = MB << 16 | ME & 0xFFFF; return 5; } - if (v >= 0 && v <= 65535) { Imm = v & 0xFFFF; return 1; } + if (isUInt16(v)) { Imm = v & 0xFFFF; return 1; } if ((v & 0x0000FFFF) == 0) { Imm = v >> 16; return 2; } break; } case ISD::XOR: case ISD::OR: - if (v >= 0 && v <= 65535) { Imm = v & 0xFFFF; return 1; } + if (isUInt16(v)) { Imm = v & 0xFFFF; return 1; } if ((v & 0x0000FFFF) == 0) { Imm = v >> 16; return 2; } break; case ISD::MUL: - if (v <= 32767 && v >= -32768) { Imm = v & 0xFFFF; return 1; } + if (isInt16(v)) { Imm = v & 0xFFFF; return 1; } break; case ISD::SUB: // handle subtract-from separately from subtract, since subi is really addi - if (U && v <= 32767 && v >= -32768) { Imm = v & 0xFFFF; return 1; } - if (!U && v <= 32768 && v >= -32767) { Imm = (-v) & 0xFFFF; return 1; } + if (U && isInt16(v)) { Imm = v & 0xFFFF; return 1; } + if (!U && isInt16(-v)) { Imm = (-v) & 0xFFFF; return 1; } break; case ISD::SETCC: - if (U && (v >= 0 && v <= 65535)) { Imm = v & 0xFFFF; return 1; } - if (!U && (v <= 32767 && v >= -32768)) { Imm = v & 0xFFFF; return 1; } + if (U && isUInt16(v)) { Imm = v & 0xFFFF; return 1; } + if (!U && isInt16(v)) { Imm = v & 0xFFFF; return 1; } break; case ISD::SDIV: - if ((Imm = ExactLog2(v))) { return 3; } - if ((Imm = ExactLog2(-v))) { Imm = -Imm; return 3; } + if (isPowerOf2_32(v)) { Imm = Log2_32(v); return 3; } + if (isPowerOf2_32(-v)) { Imm = Log2_32(-v); return 3; } if (v <= -2 || v >= 2) { return 4; } break; case ISD::UDIV: @@ -807,7 +831,7 @@ static struct ms magic(int d) { int p; unsigned int ad, anc, delta, q1, r1, q2, r2, t; - const unsigned int two31 = 2147483648U; // 2^31 + const unsigned int two31 = 0x80000000U; struct ms mag; ad = abs(d); Index: llvm/lib/Target/PowerPC/PPC32ISelSimple.cpp diff -u llvm/lib/Target/PowerPC/PPC32ISelSimple.cpp:1.143 llvm/lib/Target/PowerPC/PPC32ISelSimple.cpp:1.144 --- llvm/lib/Target/PowerPC/PPC32ISelSimple.cpp:1.143 Thu Jul 21 15:44:42 2005 +++ llvm/lib/Target/PowerPC/PPC32ISelSimple.cpp Tue Aug 2 14:25:03 2005 @@ -26,11 +26,35 @@ #include "llvm/Target/TargetMachine.h" #include "llvm/Support/GetElementPtrTypeIterator.h" #include "llvm/Support/InstVisitor.h" +#include "llvm/Support/MathExtras.h" #include "llvm/Support/Debug.h" #include "llvm/ADT/Statistic.h" #include using namespace llvm; + +// IsRunOfOnes - returns true if Val consists of one contiguous run of 1's with +// any number of 0's on either side. the 1's are allowed to wrap from LSB to +// MSB. so 0x000FFF0, 0x0000FFFF, and 0xFF0000FF are all runs. 0x0F0F0000 is +// not, since all 1's are not contiguous. +static bool IsRunOfOnes(unsigned Val, unsigned &MB, unsigned &ME) { + if (isShiftedMask_32(Val)) { + // look for the first non-zero bit + MB = CountLeadingZeros_32(Val); + // look for the first zero bit after the run of ones + ME = CountLeadingZeros_32((Val - 1) ^ Val); + return true; + } else if (isShiftedMask_32(Val = ~Val)) { // invert mask + // effectively look for the first zero bit + ME = CountLeadingZeros_32(Val) - 1; + // effectively look for the first one bit after the run of zeros + MB = CountLeadingZeros_32((Val - 1) ^ Val) + 1; + return true; + } + // no run present + return false; +} + namespace { /// TypeClass - Used by the PowerPC backend to group LLVM types by their basic /// PPC Representation. @@ -2085,73 +2109,6 @@ BuildMI(*BB, IP, Opcode, 2, DestReg).addReg(Op0r).addReg(Op1r); } -// ExactLog2 - This function solves for (Val == 1 << (N-1)) and returns N. It -// returns zero when the input is not exactly a power of two. -static unsigned ExactLog2(unsigned Val) { - if (Val == 0 || (Val & (Val-1))) return 0; - unsigned Count = 0; - while (Val != 1) { - Val >>= 1; - ++Count; - } - return Count; -} - -// isRunOfOnes - returns true if Val consists of one contiguous run of 1's with -// any number of 0's on either side. the 1's are allowed to wrap from LSB to -// MSB. so 0x000FFF0, 0x0000FFFF, and 0xFF0000FF are all runs. 0x0F0F0000 is -// not, since all 1's are not contiguous. -static bool isRunOfOnes(unsigned Val, unsigned &MB, unsigned &ME) { - bool isRun = true; - MB = 0; - ME = 0; - - // look for first set bit - int i = 0; - for (; i < 32; i++) { - if ((Val & (1 << (31 - i))) != 0) { - MB = i; - ME = i; - break; - } - } - - // look for last set bit - for (; i < 32; i++) { - if ((Val & (1 << (31 - i))) == 0) - break; - ME = i; - } - - // look for next set bit - for (; i < 32; i++) { - if ((Val & (1 << (31 - i))) != 0) - break; - } - - // if we exhausted all the bits, we found a match at this point for 0*1*0* - if (i == 32) - return true; - - // since we just encountered more 1's, if it doesn't wrap around to the - // most significant bit of the word, then we did not find a match to 1*0*1* so - // exit. - if (MB != 0) - return false; - - // look for last set bit - for (MB = i; i < 32; i++) { - if ((Val & (1 << (31 - i))) == 0) - break; - } - - // if we exhausted all the bits, then we found a match for 1*0*1*, otherwise, - // the value is not a run of ones. - if (i == 32) - return true; - return false; -} - /// isInsertAndHalf - Helper function for emitBitfieldInsert. Returns true if /// OpUser has one use, is used by an or instruction, and is itself an and whose /// second operand is a constant int. Optionally, set OrI to the Or instruction @@ -2281,7 +2238,7 @@ // succeeded in matching one of the cases for generating rlwimi. Update the // skip lists and users of the Instruction::Or. unsigned MB, ME; - if (((TgtMask ^ InsMask) == 0xFFFFFFFF) && isRunOfOnes(InsMask, MB, ME)) { + if (((TgtMask ^ InsMask) == 0xFFFFFFFF) && IsRunOfOnes(InsMask, MB, ME)) { SkipList.push_back(Op0User); SkipList.push_back(Op1User); SkipList.push_back(OptAndI); @@ -2320,7 +2277,7 @@ if (matched == false) return false; - if (isRunOfOnes(Imm, MB, ME)) { + if (IsRunOfOnes(Imm, MB, ME)) { unsigned SrcReg = getReg(Op, MBB, IP); BuildMI(*MBB, IP, PPC::RLWINM, 4, DestReg).addReg(SrcReg).addImm(Rotate) .addImm(MB).addImm(ME); @@ -2361,7 +2318,7 @@ if (Opcode == 2 && !Op1->isNullValue()) { unsigned MB, ME, mask = Op1->getRawValue(); - if (isRunOfOnes(mask, MB, ME)) { + if (IsRunOfOnes(mask, MB, ME)) { BuildMI(*MBB, IP, PPC::RLWINM, 4, DestReg).addReg(Op0Reg).addImm(0) .addImm(MB).addImm(ME); return; @@ -2582,7 +2539,9 @@ } // If the element size is exactly a power of 2, use a shift to get it. - if (unsigned Shift = ExactLog2(CI->getRawValue())) { + uint64_t C = CI->getRawValue(); + if (isPowerOf2_64(C)) { + unsigned Shift = Log2_64(C); ConstantUInt *ShiftCI = ConstantUInt::get(Type::UByteTy, Shift); emitShiftOperation(MBB, IP, Op0, ShiftCI, true, Op0->getType(), 0, DestReg); return; @@ -2729,8 +2688,8 @@ return; } - unsigned log2V = ExactLog2(V); - if (log2V != 0 && Ty->isSigned()) { + if (isPowerOf2_32(V) && Ty->isSigned()) { + unsigned log2V = Log2_32(V); unsigned Op0Reg = getReg(Op0, MBB, IP); unsigned TmpReg = makeAnotherReg(Op0->getType()); Index: llvm/lib/Target/PowerPC/PPC64ISelPattern.cpp diff -u llvm/lib/Target/PowerPC/PPC64ISelPattern.cpp:1.26 llvm/lib/Target/PowerPC/PPC64ISelPattern.cpp:1.27 --- llvm/lib/Target/PowerPC/PPC64ISelPattern.cpp:1.26 Thu Jul 21 15:44:42 2005 +++ llvm/lib/Target/PowerPC/PPC64ISelPattern.cpp Tue Aug 2 14:25:03 2005 @@ -34,7 +34,7 @@ using namespace llvm; //===----------------------------------------------------------------------===// -// PPC32TargetLowering - PPC32 Implementation of the TargetLowering interface +// PPC64TargetLowering - PPC64 Implementation of the TargetLowering interface namespace { class PPC64TargetLowering : public TargetLowering { int VarArgsFrameIndex; // FrameIndex for start of varargs area. @@ -258,6 +258,7 @@ // Just to be safe, we'll always reserve the full 48 bytes of linkage area // plus 64 bytes of argument space in case any called code gets funky on us. + // (Required by ABI to support var arg) if (NumBytes < 112) NumBytes = 112; // Adjust the stack pointer for the new arguments... @@ -397,7 +398,7 @@ Statistic<>NotLogic("ppc-codegen", "Number of inverted logical ops"); Statistic<>FusedFP("ppc-codegen", "Number of fused fp operations"); //===--------------------------------------------------------------------===// -/// ISel - PPC32 specific code to select PPC32 machine instructions for +/// ISel - PPC64 specific code to select PPC64 machine instructions for /// SelectionDAG operations. //===--------------------------------------------------------------------===// class ISel : public SelectionDAGISel { @@ -447,18 +448,6 @@ void SelectBranchCC(SDOperand N); }; -/// ExactLog2 - This function solves for (Val == 1 << (N-1)) and returns N. It -/// returns zero when the input is not exactly a power of two. -static unsigned ExactLog2(unsigned Val) { - if (Val == 0 || (Val & (Val-1))) return 0; - unsigned Count = 0; - while (Val != 1) { - Val >>= 1; - ++Count; - } - return Count; -} - /// getImmediateForOpcode - This method returns a value indicating whether /// the ConstantSDNode N can be used as an immediate to Opcode. The return /// values are either 0, 1 or 2. 0 indicates that either N is not a @@ -477,25 +466,25 @@ switch(Opcode) { default: return 0; case ISD::ADD: - if (v <= 32767 && v >= -32768) { Imm = v & 0xFFFF; return 1; } + if (isInt16(v)) { Imm = v & 0xFFFF; return 1; } if ((v & 0x0000FFFF) == 0) { Imm = v >> 16; return 2; } break; case ISD::AND: case ISD::XOR: case ISD::OR: - if (v >= 0 && v <= 65535) { Imm = v & 0xFFFF; return 1; } + if (isUInt16(v)) { Imm = v & 0xFFFF; return 1; } if ((v & 0x0000FFFF) == 0) { Imm = v >> 16; return 2; } break; case ISD::MUL: case ISD::SUB: - if (v <= 32767 && v >= -32768) { Imm = v & 0xFFFF; return 1; } + if (isInt16(v)) { Imm = v & 0xFFFF; return 1; } break; case ISD::SETCC: - if (U && (v >= 0 && v <= 65535)) { Imm = v & 0xFFFF; return 1; } - if (!U && (v <= 32767 && v >= -32768)) { Imm = v & 0xFFFF; return 1; } + if (U && isUInt16(v)) { Imm = v & 0xFFFF; return 1; } + if (!U && isInt16(v)) { Imm = v & 0xFFFF; return 1; } break; case ISD::SDIV: - if ((Imm = ExactLog2(v))) { return 3; } + if (isPowerOf2_32(v)) { Imm = Log2_32(v); return 3; } break; } return 0; @@ -1636,7 +1625,7 @@ } -/// createPPC32PatternInstructionSelector - This pass converts an LLVM function +/// createPPC64PatternInstructionSelector - This pass converts an LLVM function /// into a machine code representation using pattern matching and a machine /// description file. /// Index: llvm/lib/Target/PowerPC/PowerPCAsmPrinter.cpp diff -u llvm/lib/Target/PowerPC/PowerPCAsmPrinter.cpp:1.83 llvm/lib/Target/PowerPC/PowerPCAsmPrinter.cpp:1.84 --- llvm/lib/Target/PowerPC/PowerPCAsmPrinter.cpp:1.83 Tue Jul 26 14:03:27 2005 +++ llvm/lib/Target/PowerPC/PowerPCAsmPrinter.cpp Tue Aug 2 14:25:03 2005 @@ -698,7 +698,7 @@ O << "\t.lcomm " << Name << ",16,_global.bss_c"; } else { O << "\t.comm " << Name << "," << TD.getTypeSize(I->getType()) - << "," << log2((unsigned)TD.getTypeAlignment(I->getType())); + << "," << Log2_32((unsigned)TD.getTypeAlignment(I->getType())); } O << "\t\t# "; WriteAsOperand(O, I, true, true, &M); From brukman at cs.uiuc.edu Wed Aug 3 12:30:07 2005 From: brukman at cs.uiuc.edu (Misha Brukman) Date: Wed, 3 Aug 2005 12:30:07 -0500 Subject: [llvm-commits] CVS: llvm/lib/Target/PowerPC/PPC32ISelPattern.cpp Message-ID: <200508031730.MAA01960@zion.cs.uiuc.edu> Changes in directory llvm/lib/Target/PowerPC: PPC32ISelPattern.cpp updated: 1.113 -> 1.114 --- Log message: Fix grammar: apostrophe-s ('s) is possessive, not plural; also iff vs. if. --- Diffs of the changes: (+4 -4) PPC32ISelPattern.cpp | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-) Index: llvm/lib/Target/PowerPC/PPC32ISelPattern.cpp diff -u llvm/lib/Target/PowerPC/PPC32ISelPattern.cpp:1.113 llvm/lib/Target/PowerPC/PPC32ISelPattern.cpp:1.114 --- llvm/lib/Target/PowerPC/PPC32ISelPattern.cpp:1.113 Wed Aug 3 11:52:22 2005 +++ llvm/lib/Target/PowerPC/PPC32ISelPattern.cpp Wed Aug 3 12:29:52 2005 @@ -36,10 +36,10 @@ using namespace llvm; -// IsRunOfOnes - Returns true if Val consists of one contiguous run of 1's with -// any number of 0's on either side. the 1's are allowed to wrap from LSB to -// MSB. so 0x000FFF0, 0x0000FFFF, and 0xFF0000FF are all runs. 0x0F0F0000 is -// not, since all 1's are not contiguous. +// IsRunOfOnes - Returns true iff Val consists of one contiguous run of 1s with +// any number of 0s on either side. The 1s are allowed to wrap from LSB to +// MSB, so 0x000FFF0, 0x0000FFFF, and 0xFF0000FF are all runs. 0x0F0F0000 is +// not, since all 1s are not contiguous. static bool IsRunOfOnes(unsigned Val, unsigned &MB, unsigned &ME) { if (isShiftedMask_32(Val)) { // look for the first non-zero bit From lattner at cs.uiuc.edu Wed Aug 3 12:55:16 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Wed, 3 Aug 2005 12:55:16 -0500 Subject: [llvm-commits] CVS: llvm/lib/Analysis/CFGPrinter.cpp Message-ID: <200508031755.MAA02826@zion.cs.uiuc.edu> Changes in directory llvm/lib/Analysis: CFGPrinter.cpp updated: 1.12 -> 1.13 --- Log message: add support for Graphviz when viewing CFGs --- Diffs of the changes: (+20 -0) CFGPrinter.cpp | 20 ++++++++++++++++++++ 1 files changed, 20 insertions(+) Index: llvm/lib/Analysis/CFGPrinter.cpp diff -u llvm/lib/Analysis/CFGPrinter.cpp:1.12 llvm/lib/Analysis/CFGPrinter.cpp:1.13 --- llvm/lib/Analysis/CFGPrinter.cpp:1.12 Thu Apr 21 16:04:58 2005 +++ llvm/lib/Analysis/CFGPrinter.cpp Wed Aug 3 12:55:05 2005 @@ -24,6 +24,7 @@ #include "llvm/Assembly/Writer.h" #include "llvm/Support/CFG.h" #include "llvm/Support/GraphWriter.h" +#include "llvm/Config/config.h" #include #include using namespace llvm; @@ -137,6 +138,7 @@ /// being a 'dot' and 'gv' program in your path. /// void Function::viewCFG() const { +#ifndef NDEBUG std::string Filename = "/tmp/cfg." + getName() + ".dot"; std::cerr << "Writing '" << Filename << "'... "; std::ofstream F(Filename.c_str()); @@ -150,6 +152,17 @@ F.close(); std::cerr << "\n"; +#ifdef HAVE_GRAPHVIZ + std::cerr << "Running 'Graphviz' program... " << std::flush; + if (system((LLVM_PATH_GRAPHVIZ " " + Filename).c_str())) { + std::cerr << "Error viewing graph: 'Graphviz' not in path?\n"; + } else { + system(("rm " + Filename).c_str()); + return; + } +#endif + +#ifdef HAVE_GV std::cerr << "Running 'dot' program... " << std::flush; if (system(("dot -Tps -Nfontname=Courier -Gsize=7.5,10 " + Filename + " > /tmp/cfg.tempgraph.ps").c_str())) { @@ -159,6 +172,13 @@ system("gv /tmp/cfg.tempgraph.ps"); } system(("rm " + Filename + " /tmp/cfg.tempgraph.ps").c_str()); + return; +#endif +#endif + std::cerr << "Function::viewCFG is only available in debug builds on " + << "systems with Graphviz or gv!\n"; + + system(("rm " + Filename).c_str()); } /// viewCFGOnly - This function is meant for use from the debugger. It works From lattner at cs.uiuc.edu Wed Aug 3 12:59:57 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Wed, 3 Aug 2005 12:59:57 -0500 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Utils/SimplifyCFG.cpp Message-ID: <200508031759.MAA02910@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Utils: SimplifyCFG.cpp updated: 1.81 -> 1.82 --- Log message: Fix Transforms/SimplifyCFG/2005-08-03-PHIFactorCrash.ll, a problem that occurred while bugpointing another testcase --- Diffs of the changes: (+3 -2) SimplifyCFG.cpp | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-) Index: llvm/lib/Transforms/Utils/SimplifyCFG.cpp diff -u llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.81 llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.82 --- llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.81 Tue Aug 2 19:59:12 2005 +++ llvm/lib/Transforms/Utils/SimplifyCFG.cpp Wed Aug 3 12:59:45 2005 @@ -805,7 +805,7 @@ return Changed; } -/// HoistThenElseCodeToIf - Given a conditional branch that codes to BB1 and +/// HoistThenElseCodeToIf - Given a conditional branch that goes to BB1 and /// BB2, hoist any common code in the two blocks up into the branch block. The /// caller of this function guarantees that BI's block dominates BB1 and BB2. static bool HoistThenElseCodeToIf(BranchInst *BI) { @@ -818,7 +818,8 @@ BasicBlock *BB2 = BI->getSuccessor(1); // The false destination Instruction *I1 = BB1->begin(), *I2 = BB2->begin(); - if (I1->getOpcode() != I2->getOpcode() || !I1->isIdenticalTo(I2)) + if (I1->getOpcode() != I2->getOpcode() || !I1->isIdenticalTo(I2) || + isa(I1)) return false; // If we get here, we can hoist at least one instruction. From lattner at cs.uiuc.edu Wed Aug 3 13:01:18 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Wed, 3 Aug 2005 13:01:18 -0500 Subject: [llvm-commits] CVS: llvm/test/Regression/Transforms/SimplifyCFG/2005-08-03-PHIFactorCrash.ll Message-ID: <200508031801.NAA03012@zion.cs.uiuc.edu> Changes in directory llvm/test/Regression/Transforms/SimplifyCFG: 2005-08-03-PHIFactorCrash.ll added (r1.1) --- Log message: Testcase that used to crash simplifycfg --- Diffs of the changes: (+94 -0) 2005-08-03-PHIFactorCrash.ll | 94 +++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 94 insertions(+) Index: llvm/test/Regression/Transforms/SimplifyCFG/2005-08-03-PHIFactorCrash.ll diff -c /dev/null llvm/test/Regression/Transforms/SimplifyCFG/2005-08-03-PHIFactorCrash.ll:1.1 *** /dev/null Wed Aug 3 13:01:17 2005 --- llvm/test/Regression/Transforms/SimplifyCFG/2005-08-03-PHIFactorCrash.ll Wed Aug 3 13:01:07 2005 *************** *** 0 **** --- 1,94 ---- + ; RUN: llvm-as < %s | opt -simplifycfg -disable-output + + %arraytype.1.Char = type { int, [0 x sbyte] } + %arraytype.4.Signed = type { int, [0 x int] } + %functiontype.23 = type %structtype.Task* (%structtype.Task*, %structtype.Packet*, %structtype.FailedRun*) + %functiontype.27 = type %structtype.object* () + %functiontype.28 = type bool (%structtype.object*, %structtype.object_vtable*) + %functiontype.39 = type int (%structtype.listiter*) + %opaquetype.RuntimeTypeInfo = type sbyte* (sbyte*) + %structtype.AssertionError_vtable = type { %structtype.FailedRun_vtable } + %structtype.DeviceTask = type { %structtype.Task } + %structtype.FailedRun = type { %structtype.object } + %structtype.FailedRun_vtable = type { %structtype.object_vtable } + %structtype.Packet = type { %structtype.object, %structtype.list.1*, int, int, int, %structtype.Packet* } + %structtype.Task = type { %structtype.TaskState, %structtype.FailedRun*, int, %structtype.Packet*, %structtype.Task*, int } + %structtype.TaskState = type { %structtype.object, bool, bool, bool } + %structtype.list.1 = type { %arraytype.4.Signed* } + %structtype.listiter = type { %structtype.list.1*, int } + %structtype.object = type { %structtype.object_vtable* } + %structtype.object_vtable = type { %structtype.object_vtable*, %opaquetype.RuntimeTypeInfo*, %arraytype.1.Char*, %functiontype.27* } + %structinstance.59 = external global %structtype.AssertionError_vtable ; <%structtype.AssertionError_vtable*> [#uses=0] + + implementation ; Functions: + + declare fastcc bool %ll_isinstance__objectPtr_object_vtablePtr() + + declare fastcc void %ll_listnext__listiterPtr() + + fastcc void %WorkTask.fn() { + block0: + br label %block1 + + block1: ; preds = %block0 + %v2542 = call fastcc bool %ll_isinstance__objectPtr_object_vtablePtr( ) ; [#uses=1] + br bool %v2542, label %block4, label %block2 + + block2: ; preds = %block1 + br label %block3 + + block3: ; preds = %block2 + unwind + + block4: ; preds = %block1 + br label %block5 + + block5: ; preds = %block4 + %v2565 = seteq %structtype.Packet* null, null ; [#uses=1] + br bool %v2565, label %block15, label %block6 + + block6: ; preds = %block5 + %self_2575 = phi %structtype.DeviceTask* [ null, %block5 ] ; <%structtype.DeviceTask*> [#uses=1] + br bool false, label %block14, label %block7 + + block7: ; preds = %block14, %block6 + %self_2635 = phi %structtype.DeviceTask* [ %self_2575, %block6 ], [ null, %block14 ] ; <%structtype.DeviceTask*> [#uses=1] + %tmp.124 = getelementptr %structtype.Packet* null, int 0, uint 2 ; [#uses=0] + br label %block8 + + block8: ; preds = %block10, %block7 + %self_2672 = phi %structtype.DeviceTask* [ %self_2635, %block7 ], [ null, %block10 ] ; <%structtype.DeviceTask*> [#uses=0] + invoke fastcc void %ll_listnext__listiterPtr( ) + to label %block9 unwind label %block8_exception_handling + + block8_exception_handling: ; preds = %block8 + br bool false, label %block8_exception_found_branchto_block12, label %block8_not_exception_structinstance.10 + + block8_not_exception_structinstance.10: ; preds = %block8_exception_handling + unwind + + block8_exception_found_branchto_block12: ; preds = %block8_exception_handling + br label %block12 + + block9: ; preds = %block8 + br bool false, label %block11, label %block10 + + block10: ; preds = %block11, %block9 + br label %block8 + + block11: ; preds = %block9 + br label %block10 + + block12: ; preds = %block8_exception_found_branchto_block12 + br label %block13 + + block13: ; preds = %block15, %block12 + ret void + + block14: ; preds = %block6 + br label %block7 + + block15: ; preds = %block5 + %v2586 = phi %structtype.DeviceTask* [ null, %block5 ] ; <%structtype.DeviceTask*> [#uses=0] + br label %block13 + } From natebegeman at mac.com Wed Aug 3 13:11:34 2005 From: natebegeman at mac.com (Nate Begeman) Date: Wed, 3 Aug 2005 13:11:34 -0500 Subject: [llvm-commits] CVS: llvm/test/Regression/CodeGen/PowerPC/rlwimi2.ll rlwimi.ll Message-ID: <200508031811.NAA03186@zion.cs.uiuc.edu> Changes in directory llvm/test/Regression/CodeGen/PowerPC: rlwimi2.ll added (r1.1) rlwimi.ll updated: 1.2 -> 1.3 --- Log message: Update rlwimi tests to catch all the cases we care about --- Diffs of the changes: (+42 -2) rlwimi.ll | 14 ++++++++++++-- rlwimi2.ll | 30 ++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) Index: llvm/test/Regression/CodeGen/PowerPC/rlwimi2.ll diff -c /dev/null llvm/test/Regression/CodeGen/PowerPC/rlwimi2.ll:1.1 *** /dev/null Wed Aug 3 13:11:33 2005 --- llvm/test/Regression/CodeGen/PowerPC/rlwimi2.ll Wed Aug 3 13:11:23 2005 *************** *** 0 **** --- 1,30 ---- + ; All of these ands and shifts should be folded into rlwimi's + ; RUN: llvm-as < rlwimi2.ll | llc -march=ppc32 | grep rlwimi | wc -l | grep 3 && + ; RUN: llvm-as < rlwimi2.ll | llc -march=ppc32 | grep srwi | wc -l | grep 1 && + ; RUN: llvm-as < rlwimi2.ll | llc -march=ppc32 | not grep slwi + + implementation ; Functions: + + ushort %test1(uint %srcA, uint %srcB, uint %alpha) { + entry: + %tmp.1 = shl uint %srcA, ubyte 15 ; [#uses=1] + %tmp.4 = and uint %tmp.1, 32505856 ; [#uses=1] + %tmp.6 = and uint %srcA, 31775 ; [#uses=1] + %tmp.7 = or uint %tmp.4, %tmp.6 ; [#uses=1] + %tmp.9 = shl uint %srcB, ubyte 15 ; [#uses=1] + %tmp.12 = and uint %tmp.9, 32505856 ; [#uses=1] + %tmp.14 = and uint %srcB, 31775 ; [#uses=1] + %tmp.15 = or uint %tmp.12, %tmp.14 ; [#uses=1] + %tmp.18 = mul uint %tmp.7, %alpha ; [#uses=1] + %tmp.20 = sub uint 32, %alpha ; [#uses=1] + %tmp.22 = mul uint %tmp.15, %tmp.20 ; [#uses=1] + %tmp.23 = add uint %tmp.22, %tmp.18 ; [#uses=2] + %tmp.27 = shr uint %tmp.23, ubyte 5 ; [#uses=1] + %tmp.28 = cast uint %tmp.27 to ushort ; [#uses=1] + %tmp.29 = and ushort %tmp.28, 31775 ; [#uses=1] + %tmp.33 = shr uint %tmp.23, ubyte 20 ; [#uses=1] + %tmp.34 = cast uint %tmp.33 to ushort ; [#uses=1] + %tmp.35 = and ushort %tmp.34, 992 ; [#uses=1] + %tmp.36 = or ushort %tmp.29, %tmp.35 ; [#uses=1] + ret ushort %tmp.36 + } Index: llvm/test/Regression/CodeGen/PowerPC/rlwimi.ll diff -u llvm/test/Regression/CodeGen/PowerPC/rlwimi.ll:1.2 llvm/test/Regression/CodeGen/PowerPC/rlwimi.ll:1.3 --- llvm/test/Regression/CodeGen/PowerPC/rlwimi.ll:1.2 Sat Nov 6 15:09:46 2004 +++ llvm/test/Regression/CodeGen/PowerPC/rlwimi.ll Wed Aug 3 13:11:23 2005 @@ -1,5 +1,6 @@ ; All of these ands and shifts should be folded into rlwimi's -; RUN: llvm-as < rlwimi.ll | llc -march=ppc32 | not grep and +; RUN: llvm-as < rlwimi.ll | llc -march=ppc32 | not grep and && +; RUN: llvm-as < rlwimi.ll | llc -march=ppc32 | grep rlwimi | wc -l | grep 8 implementation ; Functions: @@ -53,10 +54,19 @@ ret int %tmp.9 } -int %test9(int %x, int %y) { +int %test7(int %x, int %y) { entry: %tmp.2 = and int %x, -65536 ; [#uses=1] %tmp.5 = and int %y, 65535 ; [#uses=1] %tmp.7 = or int %tmp.5, %tmp.2 ; [#uses=1] ret int %tmp.7 } + +uint %test8(uint %bar) { +entry: + %tmp.3 = shl uint %bar, ubyte 1 ; [#uses=1] + %tmp.4 = and uint %tmp.3, 2 ; [#uses=1] + %tmp.6 = and uint %bar, 4294967293 ; [#uses=1] + %tmp.7 = or uint %tmp.4, %tmp.6 ; [#uses=1] + ret uint %tmp.7 +} From natebegeman at mac.com Wed Aug 3 13:27:28 2005 From: natebegeman at mac.com (Nate Begeman) Date: Wed, 3 Aug 2005 13:27:28 -0500 Subject: [llvm-commits] CVS: llvm/test/Regression/CodeGen/PowerPC/rlwinm.ll Message-ID: <200508031827.NAA03611@zion.cs.uiuc.edu> Changes in directory llvm/test/Regression/CodeGen/PowerPC: rlwinm.ll added (r1.1) --- Log message: Add a couple rlwinm tests for bitfield clears --- Diffs of the changes: (+17 -0) rlwinm.ll | 17 +++++++++++++++++ 1 files changed, 17 insertions(+) Index: llvm/test/Regression/CodeGen/PowerPC/rlwinm.ll diff -c /dev/null llvm/test/Regression/CodeGen/PowerPC/rlwinm.ll:1.1 *** /dev/null Wed Aug 3 13:27:27 2005 --- llvm/test/Regression/CodeGen/PowerPC/rlwinm.ll Wed Aug 3 13:27:17 2005 *************** *** 0 **** --- 1,17 ---- + ; All of these ands and shifts should be folded into rlwimi's + ; RUN: llvm-as < rlwinm.ll | llc -march=ppc32 | not grep and && + ; RUN: llvm-as < rlwinm.ll | llc -march=ppc32 | grep rlwinm | wc -l | grep 2 + + implementation ; Functions: + + int %test1(int %a) { + entry: + %tmp.1 = and int %a, 268431360 ; [#uses=1] + ret int %tmp.1 + } + + int %test2(int %a) { + entry: + %tmp.1 = and int %a, -268435441 ; [#uses=1] + ret int %tmp.1 + } From lattner at cs.uiuc.edu Wed Aug 3 13:33:59 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Wed, 3 Aug 2005 13:33:59 -0500 Subject: [llvm-commits] CVS: llvm/test/Regression/Transforms/LowerInvoke/2005-08-03-InvokeWithPHI.ll Message-ID: <200508031833.NAA03762@zion.cs.uiuc.edu> Changes in directory llvm/test/Regression/Transforms/LowerInvoke: 2005-08-03-InvokeWithPHI.ll added (r1.1) --- Log message: new testcase for PR612: http://llvm.cs.uiuc.edu/PR612 --- Diffs of the changes: (+20 -0) 2005-08-03-InvokeWithPHI.ll | 20 ++++++++++++++++++++ 1 files changed, 20 insertions(+) Index: llvm/test/Regression/Transforms/LowerInvoke/2005-08-03-InvokeWithPHI.ll diff -c /dev/null llvm/test/Regression/Transforms/LowerInvoke/2005-08-03-InvokeWithPHI.ll:1.1 *** /dev/null Wed Aug 3 13:33:58 2005 --- llvm/test/Regression/Transforms/LowerInvoke/2005-08-03-InvokeWithPHI.ll Wed Aug 3 13:33:48 2005 *************** *** 0 **** --- 1,20 ---- + ; RUN: llvm-as < %s | opt -lowerinvoke -enable-correct-eh-support -disable-output + + implementation ; Functions: + + declare void %ll_listnext__listiterPtr() + + void %WorkTask.fn() { + block0: + invoke void %ll_listnext__listiterPtr( ) + to label %block9 unwind label %block8_exception_handling + + block8_exception_handling: ; preds = %block0 + ret void + + block9: ; preds = %block0 + %w_2690 = phi { int, int }* [ null, %block0 ] ; <{ int, int }*> [#uses=1] + %tmp.129 = getelementptr { int, int }* %w_2690, int 0, uint 1 ; [#uses=1] + %v2769 = load int* %tmp.129 ; [#uses=0] + ret void + } From lattner at cs.uiuc.edu Wed Aug 3 13:34:40 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Wed, 3 Aug 2005 13:34:40 -0500 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/LowerInvoke.cpp Message-ID: <200508031834.NAA03795@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Scalar: LowerInvoke.cpp updated: 1.26 -> 1.27 --- Log message: When inserting code, make sure not to insert it before PHI nodes. This fixes PR612: http://llvm.cs.uiuc.edu/PR612 and Transforms/LowerInvoke/2005-08-03-InvokeWithPHI.ll --- Diffs of the changes: (+3 -1) LowerInvoke.cpp | 4 +++- 1 files changed, 3 insertions(+), 1 deletion(-) Index: llvm/lib/Transforms/Scalar/LowerInvoke.cpp diff -u llvm/lib/Transforms/Scalar/LowerInvoke.cpp:1.26 llvm/lib/Transforms/Scalar/LowerInvoke.cpp:1.27 --- llvm/lib/Transforms/Scalar/LowerInvoke.cpp:1.26 Wed Jun 8 22:32:54 2005 +++ llvm/lib/Transforms/Scalar/LowerInvoke.cpp Wed Aug 3 13:34:29 2005 @@ -283,7 +283,9 @@ // Create the receiver block if there is a critical edge to the normal // destination. SplitCriticalEdge(II, 0, this); - Instruction *InsertLoc = II->getNormalDest()->begin(); + BasicBlock::iterator InsertLoc = II->getNormalDest()->begin(); + while (isa(InsertLoc)) ++InsertLoc; + // Insert a normal call instruction on the normal execution path. std::string Name = II->getName(); II->setName(""); From lattner at cs.uiuc.edu Wed Aug 3 13:51:27 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Wed, 3 Aug 2005 13:51:27 -0500 Subject: [llvm-commits] CVS: llvm/test/Regression/Transforms/LowerInvoke/2005-08-03-InvokeWithPHIUse.ll Message-ID: <200508031851.NAA04102@zion.cs.uiuc.edu> Changes in directory llvm/test/Regression/Transforms/LowerInvoke: 2005-08-03-InvokeWithPHIUse.ll added (r1.1) --- Log message: new testcase for PR612: http://llvm.cs.uiuc.edu/PR612 --- Diffs of the changes: (+16 -0) 2005-08-03-InvokeWithPHIUse.ll | 16 ++++++++++++++++ 1 files changed, 16 insertions(+) Index: llvm/test/Regression/Transforms/LowerInvoke/2005-08-03-InvokeWithPHIUse.ll diff -c /dev/null llvm/test/Regression/Transforms/LowerInvoke/2005-08-03-InvokeWithPHIUse.ll:1.1 *** /dev/null Wed Aug 3 13:51:26 2005 --- llvm/test/Regression/Transforms/LowerInvoke/2005-08-03-InvokeWithPHIUse.ll Wed Aug 3 13:51:15 2005 *************** *** 0 **** --- 1,16 ---- + ; RUN: llvm-as < %s | opt -lowerinvoke -enable-correct-eh-support -disable-output + + declare fastcc int %ll_listnext__listiterPtr() + + fastcc int %WorkTask.fn() { + block0: + %v2679 = invoke fastcc int %ll_listnext__listiterPtr( ) + to label %block9 unwind label %block8_exception_handling ; [#uses=1] + + block8_exception_handling: ; preds = %block0 + ret int 0 + + block9: ; preds = %block0 + %i_2689 = phi int [ %v2679, %block0 ] ; [#uses=0] + ret int %i_2689 + } From lattner at cs.uiuc.edu Wed Aug 3 13:51:55 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Wed, 3 Aug 2005 13:51:55 -0500 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/LowerInvoke.cpp Message-ID: <200508031851.NAA04133@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Scalar: LowerInvoke.cpp updated: 1.27 -> 1.28 --- Log message: The correct fix for PR612: http://llvm.cs.uiuc.edu/PR612 , which also fixes Transforms/LowerInvoke/2005-08-03-InvokeWithPHIUse.ll --- Diffs of the changes: (+12 -2) LowerInvoke.cpp | 14 ++++++++++++-- 1 files changed, 12 insertions(+), 2 deletions(-) Index: llvm/lib/Transforms/Scalar/LowerInvoke.cpp diff -u llvm/lib/Transforms/Scalar/LowerInvoke.cpp:1.27 llvm/lib/Transforms/Scalar/LowerInvoke.cpp:1.28 --- llvm/lib/Transforms/Scalar/LowerInvoke.cpp:1.27 Wed Aug 3 13:34:29 2005 +++ llvm/lib/Transforms/Scalar/LowerInvoke.cpp Wed Aug 3 13:51:44 2005 @@ -283,10 +283,20 @@ // Create the receiver block if there is a critical edge to the normal // destination. SplitCriticalEdge(II, 0, this); - BasicBlock::iterator InsertLoc = II->getNormalDest()->begin(); - while (isa(InsertLoc)) ++InsertLoc; + // There should not be any PHI nodes in II->getNormalDest() now. It has + // a single predecessor, so any PHI nodes are unneeded. Remove them now + // by replacing them with their single input value. + assert(II->getNormalDest()->getSinglePredecessor() && + "Split crit edge doesn't have a single predecessor!"); + BasicBlock::iterator InsertLoc = II->getNormalDest()->begin(); + while (PHINode *PN = dyn_cast(InsertLoc)) { + PN->replaceAllUsesWith(PN->getIncomingValue(0)); + PN->eraseFromParent(); + InsertLoc = II->getNormalDest()->begin(); + } + // Insert a normal call instruction on the normal execution path. std::string Name = II->getName(); II->setName(""); CallInst *NewCall = new CallInst(II->getCalledValue(), From lattner at cs.uiuc.edu Wed Aug 3 15:31:49 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Wed, 3 Aug 2005 15:31:49 -0500 Subject: [llvm-commits] CVS: llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp SelectionDAGPrinter.cpp Message-ID: <200508032031.PAA09646@zion.cs.uiuc.edu> Changes in directory llvm/lib/CodeGen/SelectionDAG: LegalizeDAG.cpp updated: 1.151 -> 1.152 SelectionDAGPrinter.cpp updated: 1.16 -> 1.17 --- Log message: Fix PR611: http://llvm.cs.uiuc.edu/PR611 , codegen'ing SREM of FP operands to fmod or fmodf instead of the sequence used for integer ops --- Diffs of the changes: (+14 -6) LegalizeDAG.cpp | 18 ++++++++++++------ SelectionDAGPrinter.cpp | 2 ++ 2 files changed, 14 insertions(+), 6 deletions(-) Index: llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp diff -u llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:1.151 llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:1.152 --- llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:1.151 Mon Aug 1 13:16:37 2005 +++ llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp Wed Aug 3 15:31:37 2005 @@ -1306,12 +1306,18 @@ case TargetLowering::Promote: case TargetLowering::Custom: assert(0 && "Cannot promote/custom handle this yet!"); - case TargetLowering::Expand: { - MVT::ValueType VT = Node->getValueType(0); - unsigned Opc = (Node->getOpcode() == ISD::UREM) ? ISD::UDIV : ISD::SDIV; - Result = DAG.getNode(Opc, VT, Tmp1, Tmp2); - Result = DAG.getNode(ISD::MUL, VT, Result, Tmp2); - Result = DAG.getNode(ISD::SUB, VT, Tmp1, Result); + case TargetLowering::Expand: + if (MVT::isInteger(Node->getValueType(0))) { + MVT::ValueType VT = Node->getValueType(0); + unsigned Opc = (Node->getOpcode() == ISD::UREM) ? ISD::UDIV : ISD::SDIV; + Result = DAG.getNode(Opc, VT, Tmp1, Tmp2); + Result = DAG.getNode(ISD::MUL, VT, Result, Tmp2); + Result = DAG.getNode(ISD::SUB, VT, Tmp1, Result); + } else { + // Floating point mod -> fmod libcall. + const char *FnName = Node->getValueType(0) == MVT::f32 ? "fmodf":"fmod"; + SDOperand Dummy; + Result = ExpandLibCall(FnName, Node, Dummy); } break; } Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp diff -u llvm/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp:1.16 llvm/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp:1.17 --- llvm/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp:1.16 Fri Jul 15 17:48:31 2005 +++ llvm/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp Wed Aug 3 15:31:37 2005 @@ -124,6 +124,7 @@ if (system((LLVM_PATH_GRAPHVIZ " " + Filename).c_str())) { std::cerr << "Error viewing graph: 'Graphviz' not in path?\n"; } else { + system(("rm " + Filename).c_str()); return; } #endif @@ -143,4 +144,5 @@ #endif std::cerr << "SelectionDAG::viewGraph is only available in debug builds on " << "systems with Graphviz or gv!\n"; + system(("rm " + Filename).c_str()); } From lattner at cs.uiuc.edu Wed Aug 3 15:53:30 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Wed, 3 Aug 2005 15:53:30 -0500 Subject: [llvm-commits] CVS: llvm/include/llvm/Support/MathExtras.h Message-ID: <200508032053.PAA09850@zion.cs.uiuc.edu> Changes in directory llvm/include/llvm/Support: MathExtras.h updated: 1.22 -> 1.23 --- Log message: Fix an obvious bug in the Log2 stuff that broke SingleSource/UnitTests/2005-05-12-Int64ToFP last night. --- Diffs of the changes: (+1 -1) MathExtras.h | 2 +- 1 files changed, 1 insertion(+), 1 deletion(-) Index: llvm/include/llvm/Support/MathExtras.h diff -u llvm/include/llvm/Support/MathExtras.h:1.22 llvm/include/llvm/Support/MathExtras.h:1.23 --- llvm/include/llvm/Support/MathExtras.h:1.22 Wed Aug 3 11:53:58 2005 +++ llvm/include/llvm/Support/MathExtras.h Wed Aug 3 15:53:19 2005 @@ -164,7 +164,7 @@ // Log2_64 - This function returns the floor log base 2 of the specified value, // -1 if the value is zero. (64 bit edition.) -inline unsigned Log2_64(unsigned Value) { +inline unsigned Log2_64(uint64_t Value) { return 63 - CountLeadingZeros_64(Value); } From lattner at cs.uiuc.edu Wed Aug 3 16:01:57 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Wed, 3 Aug 2005 16:01:57 -0500 Subject: [llvm-commits] CVS: llvm/test/Regression/CodeGen/X86/fast-cc-tail-call.ll Message-ID: <200508032101.QAA10030@zion.cs.uiuc.edu> Changes in directory llvm/test/Regression/CodeGen/X86: fast-cc-tail-call.ll updated: 1.1 -> 1.2 --- Log message: Fix this to test the BE we care about --- Diffs of the changes: (+1 -1) fast-cc-tail-call.ll | 2 +- 1 files changed, 1 insertion(+), 1 deletion(-) Index: llvm/test/Regression/CodeGen/X86/fast-cc-tail-call.ll diff -u llvm/test/Regression/CodeGen/X86/fast-cc-tail-call.ll:1.1 llvm/test/Regression/CodeGen/X86/fast-cc-tail-call.ll:1.2 --- llvm/test/Regression/CodeGen/X86/fast-cc-tail-call.ll:1.1 Sun May 15 00:52:51 2005 +++ llvm/test/Regression/CodeGen/X86/fast-cc-tail-call.ll Wed Aug 3 16:01:46 2005 @@ -1,4 +1,4 @@ -; RUN: llvm-as < %s | llc -x86-asm-syntax=intel -enable-x86-fastcc | not grep call +; RUN: llvm-as < %s | llc -march=x86 -x86-asm-syntax=intel -enable-x86-fastcc | not grep call fastcc int %bar(int %X, int(double, int) *%FP) { %Y = tail call fastcc int %FP(double 0.0, int %X) From lattner at cs.uiuc.edu Wed Aug 3 16:36:20 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Wed, 3 Aug 2005 16:36:20 -0500 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp Message-ID: <200508032136.QAA17999@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Scalar: LoopStrengthReduce.cpp updated: 1.22 -> 1.23 --- Log message: Fix a nasty dangling pointer issue. The ScalarEvolution pass would keep a map from instruction* to SCEVHandles. When we delete instructions, we have to tell it about it. We would run into nasty cases where new instructions were reallocated at old instruction addresses and get the old map values. Bad bad bad :( --- Diffs of the changes: (+3 -1) LoopStrengthReduce.cpp | 4 +++- 1 files changed, 3 insertions(+), 1 deletion(-) Index: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp diff -u llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.22 llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.23 --- llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.22 Mon Aug 1 22:31:14 2005 +++ llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp Wed Aug 3 16:36:09 2005 @@ -149,7 +149,8 @@ for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i) if (Instruction *U = dyn_cast(I->getOperand(i))) Insts.insert(U); - I->getParent()->getInstList().erase(I); + SE->deleteInstructionFromRecords(I); + I->eraseFromParent(); Changed = true; } } @@ -661,6 +662,7 @@ DeadInsts.insert(BO); // Break the cycle, then delete the PHI. PN->replaceAllUsesWith(UndefValue::get(PN->getType())); + SE->deleteInstructionFromRecords(PN); PN->eraseFromParent(); } } From lattner at cs.uiuc.edu Wed Aug 3 17:21:16 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Wed, 3 Aug 2005 17:21:16 -0500 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp Message-ID: <200508032221.RAA18200@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Scalar: LoopStrengthReduce.cpp updated: 1.23 -> 1.24 --- Log message: Rename IVUse to IVUsersOfOneStride, use a struct instead of a pair to unify some parallel vectors and get field names more descriptive than "first" and "second". This isn't lisp afterall :) --- Diffs of the changes: (+41 -25) LoopStrengthReduce.cpp | 66 ++++++++++++++++++++++++++++++------------------- 1 files changed, 41 insertions(+), 25 deletions(-) Index: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp diff -u llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.23 llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.24 --- llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.23 Wed Aug 3 16:36:09 2005 +++ llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp Wed Aug 3 17:21:05 2005 @@ -50,16 +50,31 @@ PHINode *CachedPHINode; std::map Map; }; - - struct IVUse { + + /// IVStrideUse - Keep track of one use of a strided induction variable, where + /// the stride is stored externally. The Offset member keeps track of the + /// offset from the IV, User is the actual user of the operand, and 'Operand' + /// is the operand # of the User that is the use. + struct IVStrideUse { + SCEVHandle Offset; + Instruction *User; + Value *OperandValToReplace; + + IVStrideUse(const SCEVHandle &Offs, Instruction *U, Value *O) + : Offset(Offs), User(U), OperandValToReplace(O) {} + }; + + /// IVUsersOfOneStride - This structure keeps track of all instructions that + /// have an operand that is based on the trip count multiplied by some stride. + /// The stride for all of these users is common and kept external to this + /// structure. + struct IVUsersOfOneStride { /// Users - Keep track of all of the users of this stride as well as the - /// initial value. - std::vector > Users; - std::vector UserOperands; - - void addUser(SCEVHandle &SH, Instruction *U, Instruction *V) { - Users.push_back(std::make_pair(SH, U)); - UserOperands.push_back(V); + /// initial value and the operand that uses the IV. + std::vector Users; + + void addUser(const SCEVHandle &Offset,Instruction *User, Value *Operand) { + Users.push_back(IVStrideUse(Offset, User, Operand)); } }; @@ -78,7 +93,7 @@ /// IVUsesByStride - Keep track of all uses of induction variables that we /// are interested in. The key of the map is the stride of the access. - std::map IVUsesByStride; + std::map IVUsesByStride; /// CastedBasePointers - As we need to lower getelementptr instructions, we /// cast the pointer input to uintptr_t. This keeps track of the casted @@ -120,8 +135,8 @@ void AnalyzeGetElementPtrUsers(GetElementPtrInst *GEP, Instruction *I, Loop *L); - void StrengthReduceStridedIVUsers(Value *Stride, IVUse &Uses, Loop *L, - bool isOnlyStride); + void StrengthReduceStridedIVUsers(Value *Stride, IVUsersOfOneStride &Uses, + Loop *L, bool isOnlyStride); void strengthReduceGEP(GetElementPtrInst *GEPI, Loop *L, GEPCache* GEPCache, @@ -339,7 +354,6 @@ DEBUG(std::cerr << "FOUND USER: " << *User << " OF STRIDE: " << *Step << " BASE = " << *Base << "\n"); - // Okay, we found a user that we cannot reduce. Analyze the instruction // and decide what to do with it. IVUsesByStride[Step].addUser(Base, User, GEP); @@ -410,8 +424,9 @@ /// Inst - The instruction using the induction variable. Instruction *Inst; - /// Op - The value to replace with the EmittedBase. - Value *Op; + /// OperandValToReplace - The operand value of Inst to replace with the + /// EmittedBase. + Value *OperandValToReplace; /// Imm - The immediate value that should be added to the base immediately /// before Inst, because it will be folded into the imm field of the @@ -422,8 +437,8 @@ /// operation. This is null if we should just use zero so far. Value *EmittedBase; - BasedUser(Instruction *I, Value *V, const SCEVHandle &IMM) - : Inst(I), Op(V), Imm(IMM), EmittedBase(0) {} + BasedUser(Instruction *I, Value *Op, const SCEVHandle &IMM) + : Inst(I), OperandValToReplace(Op), Imm(IMM), EmittedBase(0) {} // No need to compare these. @@ -490,7 +505,8 @@ /// stride of IV. All of the users may have different starting values, and this /// may not be the only stride (we know it is if isOnlyStride is true). void LoopStrengthReduce::StrengthReduceStridedIVUsers(Value *Stride, - IVUse &Uses, Loop *L, + IVUsersOfOneStride &Uses, + Loop *L, bool isOnlyStride) { // Transform our list of users and offsets to a bit more complex table. In // this new vector, the first entry for each element is the base of the @@ -501,12 +517,12 @@ UsersToProcess.reserve(Uses.Users.size()); SCEVHandle ZeroBase = SCEVUnknown::getIntegerSCEV(0, - Uses.Users[0].first->getType()); + Uses.Users[0].Offset->getType()); for (unsigned i = 0, e = Uses.Users.size(); i != e; ++i) - UsersToProcess.push_back(std::make_pair(Uses.Users[i].first, - BasedUser(Uses.Users[i].second, - Uses.UserOperands[i], + UsersToProcess.push_back(std::make_pair(Uses.Users[i].Offset, + BasedUser(Uses.Users[i].User, + Uses.Users[i].OperandValToReplace, ZeroBase))); // First pass, figure out what we can represent in the immediate fields of @@ -547,7 +563,7 @@ while (!UsersToProcess.empty()) { // Create a new Phi for this base, and stick it in the loop header. - Value *Replaced = UsersToProcess.front().second.Op; + Value *Replaced = UsersToProcess.front().second.OperandValToReplace; const Type *ReplacedTy = Replaced->getType(); PHINode *NewPHI = new PHINode(ReplacedTy, Replaced->getName()+".str", PhiInsertBefore); @@ -630,8 +646,8 @@ // If we only have one stride, we can more aggressively eliminate some things. bool HasOneStride = IVUsesByStride.size() == 1; - for (std::map::iterator SI = IVUsesByStride.begin(), - E = IVUsesByStride.end(); SI != E; ++SI) + for (std::map::iterator SI + = IVUsesByStride.begin(), E = IVUsesByStride.end(); SI != E; ++SI) StrengthReduceStridedIVUsers(SI->first, SI->second, L, HasOneStride); // Clean up after ourselves From alenhar2 at cs.uiuc.edu Wed Aug 3 17:33:32 2005 From: alenhar2 at cs.uiuc.edu (Andrew Lenharth) Date: Wed, 3 Aug 2005 17:33:32 -0500 Subject: [llvm-commits] CVS: llvm/lib/Target/Alpha/AlphaTargetMachine.cpp Message-ID: <200508032233.RAA18256@zion.cs.uiuc.edu> Changes in directory llvm/lib/Target/Alpha: AlphaTargetMachine.cpp updated: 1.10 -> 1.11 --- Log message: Alpha ABI specifies stack is always 16 byte alligned, and gcc does it, so I will too --- Diffs of the changes: (+1 -1) AlphaTargetMachine.cpp | 2 +- 1 files changed, 1 insertion(+), 1 deletion(-) Index: llvm/lib/Target/Alpha/AlphaTargetMachine.cpp diff -u llvm/lib/Target/Alpha/AlphaTargetMachine.cpp:1.10 llvm/lib/Target/Alpha/AlphaTargetMachine.cpp:1.11 --- llvm/lib/Target/Alpha/AlphaTargetMachine.cpp:1.10 Fri Jul 22 16:00:30 2005 +++ llvm/lib/Target/Alpha/AlphaTargetMachine.cpp Wed Aug 3 17:33:21 2005 @@ -60,7 +60,7 @@ AlphaTargetMachine::AlphaTargetMachine( const Module &M, IntrinsicLowering *IL) : TargetMachine("alpha", IL, true), - FrameInfo(TargetFrameInfo::StackGrowsDown, 8, 0), //TODO: check these + FrameInfo(TargetFrameInfo::StackGrowsDown, 16, 0), JITInfo(*this) {} From lattner at cs.uiuc.edu Wed Aug 3 17:51:33 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Wed, 3 Aug 2005 17:51:33 -0500 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp Message-ID: <200508032251.RAA18382@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Scalar: LoopStrengthReduce.cpp updated: 1.24 -> 1.25 --- Log message: Move from Stage 0 to Stage 1. Only emit one PHI node for IV uses with identical bases and strides (after moving foldable immediates to the load/store instruction). This implements LoopStrengthReduce/dont_insert_redundant_ops.ll, allowing us to generate this PPC code for test1: or r30, r3, r3 .LBB_test1_1: ; Loop li r2, 0 stw r2, 0(r30) stw r2, 4(r30) bl L_pred$stub addi r30, r30, 8 cmplwi cr0, r3, 0 bne .LBB_test1_1 ; Loop instead of this code: or r30, r3, r3 or r29, r3, r3 .LBB_test1_1: ; Loop li r2, 0 stw r2, 0(r29) stw r2, 4(r30) bl L_pred$stub addi r30, r30, 8 ;; Two iv's with step of 8 addi r29, r29, 8 cmplwi cr0, r3, 0 bne .LBB_test1_1 ; Loop --- Diffs of the changes: (+34 -30) LoopStrengthReduce.cpp | 64 ++++++++++++++++++++++++++----------------------- 1 files changed, 34 insertions(+), 30 deletions(-) Index: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp diff -u llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.24 llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.25 --- llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.24 Wed Aug 3 17:21:05 2005 +++ llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp Wed Aug 3 17:51:21 2005 @@ -554,24 +554,25 @@ SomeLoopPHI->getIncomingBlock(SomeLoopPHI->getIncomingBlock(0) == Preheader); // FIXME: This loop needs increasing levels of intelligence. - // STAGE 0: just emit everything as its own base. <-- We are here + // STAGE 0: just emit everything as its own base. // STAGE 1: factor out common vars from bases, and try and push resulting - // constants into Imm field. + // constants into Imm field. <-- We are here // STAGE 2: factor out large constants to try and make more constants // acceptable for target loads and stores. - std::sort(UsersToProcess.begin(), UsersToProcess.end()); + // Sort by the base value, so that all IVs with identical bases are next to + // each other. + std::sort(UsersToProcess.begin(), UsersToProcess.end()); while (!UsersToProcess.empty()) { + SCEVHandle Base = UsersToProcess.front().first; + // Create a new Phi for this base, and stick it in the loop header. - Value *Replaced = UsersToProcess.front().second.OperandValToReplace; - const Type *ReplacedTy = Replaced->getType(); - PHINode *NewPHI = new PHINode(ReplacedTy, Replaced->getName()+".str", - PhiInsertBefore); + const Type *ReplacedTy = Base->getType(); + PHINode *NewPHI = new PHINode(ReplacedTy, "iv.", PhiInsertBefore); // Emit the initial base value into the loop preheader, and add it to the // Phi node. - Value *BaseV = Rewriter.expandCodeFor(UsersToProcess.front().first, - PreInsertPt, ReplacedTy); + Value *BaseV = Rewriter.expandCodeFor(Base, PreInsertPt, ReplacedTy); NewPHI->addIncoming(BaseV, Preheader); // Emit the increment of the base value before the terminator of the loop @@ -585,28 +586,31 @@ NewPHI->addIncoming(IncV, LatchBlock); // Emit the code to add the immediate offset to the Phi value, just before - // the instruction that we identified as using this stride and base. - // First, empty the SCEVExpander's expression map so that we are guaranteed - // to have the code emitted where we expect it. - Rewriter.clear(); - SCEVHandle NewValSCEV = SCEVAddExpr::get(SCEVUnknown::get(NewPHI), - UsersToProcess.front().second.Imm); - Value *newVal = Rewriter.expandCodeFor(NewValSCEV, - UsersToProcess.front().second.Inst, - ReplacedTy); - - // Replace the use of the operand Value with the new Phi we just created. - DEBUG(std::cerr << "REPLACING: " << *Replaced << "IN: " << - *UsersToProcess.front().second.Inst << "WITH: "<< *newVal << '\n'); - UsersToProcess.front().second.Inst->replaceUsesOfWith(Replaced, newVal); - - // Mark old value we replaced as possibly dead, so that it is elminated - // if we just replaced the last use of that value. - DeadInsts.insert(cast(Replaced)); - - UsersToProcess.erase(UsersToProcess.begin()); - ++NumReduced; + // the instructions that we identified as using this stride and base. + while (!UsersToProcess.empty() && UsersToProcess.front().first == Base) { + BasedUser &User = UsersToProcess.front().second; + + // Clear the SCEVExpander's expression map so that we are guaranteed + // to have the code emitted where we expect it. + Rewriter.clear(); + SCEVHandle NewValSCEV = SCEVAddExpr::get(SCEVUnknown::get(NewPHI), + User.Imm); + Value *Replaced = UsersToProcess.front().second.OperandValToReplace; + Value *newVal = Rewriter.expandCodeFor(NewValSCEV, User.Inst, + Replaced->getType()); + + // Replace the use of the operand Value with the new Phi we just created. + DEBUG(std::cerr << "REPLACING: " << *Replaced << "IN: " << + *User.Inst << "WITH: "<< *newVal << '\n'); + User.Inst->replaceUsesOfWith(Replaced, newVal); + + // Mark old value we replaced as possibly dead, so that it is elminated + // if we just replaced the last use of that value. + DeadInsts.insert(cast(Replaced)); + UsersToProcess.erase(UsersToProcess.begin()); + ++NumReduced; + } // TODO: Next, find out which base index is the most common, pull it out. } From lattner at cs.uiuc.edu Wed Aug 3 17:51:51 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Wed, 3 Aug 2005 17:51:51 -0500 Subject: [llvm-commits] CVS: llvm/test/Regression/Transforms/LoopStrengthReduce/dont_insert_redundant_ops.ll Message-ID: <200508032251.RAA18417@zion.cs.uiuc.edu> Changes in directory llvm/test/Regression/Transforms/LoopStrengthReduce: dont_insert_redundant_ops.ll updated: 1.3 -> 1.4 --- Log message: this now passes --- Diffs of the changes: (+0 -2) dont_insert_redundant_ops.ll | 2 -- 1 files changed, 2 deletions(-) Index: llvm/test/Regression/Transforms/LoopStrengthReduce/dont_insert_redundant_ops.ll diff -u llvm/test/Regression/Transforms/LoopStrengthReduce/dont_insert_redundant_ops.ll:1.3 llvm/test/Regression/Transforms/LoopStrengthReduce/dont_insert_redundant_ops.ll:1.4 --- llvm/test/Regression/Transforms/LoopStrengthReduce/dont_insert_redundant_ops.ll:1.3 Mon Aug 1 12:10:50 2005 +++ llvm/test/Regression/Transforms/LoopStrengthReduce/dont_insert_redundant_ops.ll Wed Aug 3 17:51:40 2005 @@ -1,8 +1,6 @@ ; Check that this test makes INDVAR and related stuff dead. ; RUN: llvm-as < %s | opt -loop-reduce | llvm-dis | grep phi | wc -l | grep 2 -; XFAIL: * - declare bool %pred() void %test1({ int, int }* %P) { From natebegeman at mac.com Wed Aug 3 18:26:39 2005 From: natebegeman at mac.com (Nate Begeman) Date: Wed, 3 Aug 2005 18:26:39 -0500 Subject: [llvm-commits] CVS: llvm/lib/Target/X86/X86ISelPattern.cpp X86InstrInfo.td Message-ID: <200508032326.SAA18626@zion.cs.uiuc.edu> Changes in directory llvm/lib/Target/X86: X86ISelPattern.cpp updated: 1.163 -> 1.164 X86InstrInfo.td updated: 1.130 -> 1.131 --- Log message: Scalar SSE: load +0.0 -> xorps/xorpd Scalar SSE: a < b ? c : 0.0 -> cmpss, andps Scalar SSE: float -> i16 needs to be promoted --- Diffs of the changes: (+133 -80) X86ISelPattern.cpp | 202 ++++++++++++++++++++++++++++++++--------------------- X86InstrInfo.td | 11 ++ 2 files changed, 133 insertions(+), 80 deletions(-) Index: llvm/lib/Target/X86/X86ISelPattern.cpp diff -u llvm/lib/Target/X86/X86ISelPattern.cpp:1.163 llvm/lib/Target/X86/X86ISelPattern.cpp:1.164 --- llvm/lib/Target/X86/X86ISelPattern.cpp:1.163 Tue Aug 2 14:25:03 2005 +++ llvm/lib/Target/X86/X86ISelPattern.cpp Wed Aug 3 18:26:28 2005 @@ -189,6 +189,7 @@ // SSE has no i16 to fp conversion, only i32 setOperationAction(ISD::SINT_TO_FP, MVT::i16, Promote); + setOperationAction(ISD::FP_TO_SINT, MVT::i16, Promote); // We don't support sin/cos/sqrt/fmod setOperationAction(ISD::FSIN , MVT::f64, Expand); @@ -201,6 +202,8 @@ setOperationAction(ISD::FABS , MVT::f32, Expand); setOperationAction(ISD::FNEG , MVT::f32, Expand); setOperationAction(ISD::SREM , MVT::f32, Expand); + + addLegalFPImmediate(+0.0); // xorps / xorpd } else { // Set up the FP register classes. addRegisterClass(MVT::f64, X86::RFPRegisterClass); @@ -1114,8 +1117,8 @@ bool EmitOrOpOp(SDOperand Op1, SDOperand Op2, unsigned DestReg); void EmitCMP(SDOperand LHS, SDOperand RHS, bool isOnlyUse); bool EmitBranchCC(MachineBasicBlock *Dest, SDOperand Chain, SDOperand Cond); - void EmitSelectCC(SDOperand Cond, MVT::ValueType SVT, - unsigned RTrue, unsigned RFalse, unsigned RDest); + void EmitSelectCC(SDOperand Cond, SDOperand True, SDOperand False, + MVT::ValueType SVT, unsigned RDest); unsigned SelectExpr(SDOperand N); X86AddressMode SelectAddrExprs(const X86ISelAddressMode &IAM); @@ -1747,11 +1750,11 @@ } /// EmitSelectCC - Emit code into BB that performs a select operation between -/// the two registers RTrue and RFalse, generating a result into RDest. Return -/// true if the fold cannot be performed. +/// the two registers RTrue and RFalse, generating a result into RDest. /// -void ISel::EmitSelectCC(SDOperand Cond, MVT::ValueType SVT, - unsigned RTrue, unsigned RFalse, unsigned RDest) { +void ISel::EmitSelectCC(SDOperand Cond, SDOperand True, SDOperand False, + MVT::ValueType SVT, unsigned RDest) { + unsigned RTrue, RFalse; enum Condition { EQ, NE, LT, LE, GT, GE, B, BE, A, AE, P, NP, NOT_SET @@ -1773,12 +1776,13 @@ X86::FCMOVA , X86::FCMOVAE, X86::FCMOVP , X86::FCMOVNP }; static const int SSE_CMOVTAB[] = { - 0 /* CMPEQSS */, 4 /* CMPNEQSS */, 1 /* CMPLTSS */, 2 /* CMPLESS */, - 1 /* CMPLTSS */, 2 /* CMPLESS */, /*missing*/0, /*missing*/0, - /*missing*/0, /*missing*/0, /*missing*/0, /*missing*/0 + /*CMPEQ*/ 0, /*CMPNEQ*/ 4, /*missing*/ 0, /*missing*/ 0, + /*missing*/ 0, /*missing*/ 0, /*CMPLT*/ 1, /*CMPLE*/ 2, + /*CMPNLE*/ 6, /*CMPNLT*/ 5, /*CMPUNORD*/ 3, /*CMPORD*/ 7 }; - - if (SetCCSDNode *SetCC = dyn_cast(Cond)) { + + SetCCSDNode *SetCC; + if ((SetCC = dyn_cast(Cond))) { if (MVT::isInteger(SetCC->getOperand(0).getValueType())) { switch (SetCC->getCondition()) { default: assert(0 && "Unknown integer comparison!"); @@ -1793,20 +1797,6 @@ case ISD::SETULE: CondCode = BE; break; case ISD::SETUGE: CondCode = AE; break; } - } else if (X86ScalarSSE) { - switch (SetCC->getCondition()) { - default: assert(0 && "Unknown scalar fp comparison!"); - case ISD::SETEQ: CondCode = EQ; break; - case ISD::SETNE: CondCode = NE; break; - case ISD::SETULT: - case ISD::SETLT: CondCode = LT; break; - case ISD::SETULE: - case ISD::SETLE: CondCode = LE; break; - case ISD::SETUGT: - case ISD::SETGT: CondCode = GT; break; - case ISD::SETUGE: - case ISD::SETGE: CondCode = GE; break; - } } else { // On a floating point condition, the flags are set as follows: // ZF PF CF op @@ -1843,55 +1833,106 @@ } } - // There's no SSE equivalent of FCMOVE. In some cases we can fake it up, in - // Others we will have to do the PowerPC thing and generate an MBB for the - // true and false values and select between them with a PHI. + // There's no SSE equivalent of FCMOVE. For cases where we set a condition + // code above and one of the results of the select is +0.0, then we can fake + // it up through a clever AND with mask. Otherwise, we will fall through to + // the code below that will use a PHI node to select the right value. if (X86ScalarSSE && (SVT == MVT::f32 || SVT == MVT::f64)) { - if (0 && CondCode != NOT_SET) { - // FIXME: check for min and max - } else { - // FIXME: emit a direct compare and branch rather than setting a cond reg - // and testing it. - unsigned CondReg = SelectExpr(Cond); - BuildMI(BB, X86::TEST8rr, 2).addReg(CondReg).addReg(CondReg); - - // Create an iterator with which to insert the MBB for copying the false - // value and the MBB to hold the PHI instruction for this SetCC. - MachineBasicBlock *thisMBB = BB; - const BasicBlock *LLVM_BB = BB->getBasicBlock(); - ilist::iterator It = BB; - ++It; - - // thisMBB: - // ... - // TrueVal = ... - // cmpTY ccX, r1, r2 - // bCC sinkMBB - // fallthrough --> copy0MBB - MachineBasicBlock *copy0MBB = new MachineBasicBlock(LLVM_BB); - MachineBasicBlock *sinkMBB = new MachineBasicBlock(LLVM_BB); - BuildMI(BB, X86::JNE, 1).addMBB(sinkMBB); - MachineFunction *F = BB->getParent(); - F->getBasicBlockList().insert(It, copy0MBB); - F->getBasicBlockList().insert(It, sinkMBB); - // Update machine-CFG edges - BB->addSuccessor(copy0MBB); - BB->addSuccessor(sinkMBB); - - // copy0MBB: - // %FalseValue = ... - // # fallthrough to sinkMBB - BB = copy0MBB; - // Update machine-CFG edges - BB->addSuccessor(sinkMBB); - - // sinkMBB: - // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ] - // ... - BB = sinkMBB; - BuildMI(BB, X86::PHI, 4, RDest).addReg(RFalse) - .addMBB(copy0MBB).addReg(RTrue).addMBB(thisMBB); + if (SetCC && SetCC->getOperand(0).getValueType() == SVT && + NOT_SET != CondCode) { + ConstantFPSDNode *CT = dyn_cast(True); + ConstantFPSDNode *CF = dyn_cast(False); + bool TrueZero = CT && CT->isExactlyValue(0.0); + bool FalseZero = CF && CF->isExactlyValue(0.0); + if (TrueZero || FalseZero) { + SDOperand LHS = Cond.getOperand(0); + SDOperand RHS = Cond.getOperand(1); + + // Select the two halves of the condition + unsigned RLHS, RRHS; + if (getRegPressure(LHS) > getRegPressure(RHS)) { + RLHS = SelectExpr(LHS); + RRHS = SelectExpr(RHS); + } else { + RRHS = SelectExpr(RHS); + RLHS = SelectExpr(LHS); + } + + // Emit the comparison and generate a mask from it + unsigned MaskReg = MakeReg(SVT); + unsigned Opc = (SVT == MVT::f32) ? X86::CMPSSrr : X86::CMPSDrr; + BuildMI(BB, Opc, 3, MaskReg).addReg(RLHS).addReg(RRHS) + .addImm(SSE_CMOVTAB[CondCode]); + + if (TrueZero) { + RFalse = SelectExpr(False); + Opc = (SVT == MVT::f32) ? X86::ANDNPSrr : X86::ANDNPDrr; + BuildMI(BB, Opc, 2, RDest).addReg(MaskReg).addReg(RFalse); + } else { + RTrue = SelectExpr(True); + Opc = (SVT == MVT::f32) ? X86::ANDPSrr : X86::ANDPDrr; + BuildMI(BB, Opc, 2, RDest).addReg(MaskReg).addReg(RTrue); + } + return; + } } + } + + // Select the true and false values for use in both the SSE PHI case, and the + // integer or x87 cmov cases below. + if (getRegPressure(True) > getRegPressure(False)) { + RTrue = SelectExpr(True); + RFalse = SelectExpr(False); + } else { + RFalse = SelectExpr(False); + RTrue = SelectExpr(True); + } + + // Since there's no SSE equivalent of FCMOVE, and we couldn't generate an + // AND with mask, we'll have to do the normal RISC thing and generate a PHI + // node to select between the true and false values. + if (X86ScalarSSE && (SVT == MVT::f32 || SVT == MVT::f64)) { + // FIXME: emit a direct compare and branch rather than setting a cond reg + // and testing it. + unsigned CondReg = SelectExpr(Cond); + BuildMI(BB, X86::TEST8rr, 2).addReg(CondReg).addReg(CondReg); + + // Create an iterator with which to insert the MBB for copying the false + // value and the MBB to hold the PHI instruction for this SetCC. + MachineBasicBlock *thisMBB = BB; + const BasicBlock *LLVM_BB = BB->getBasicBlock(); + ilist::iterator It = BB; + ++It; + + // thisMBB: + // ... + // TrueVal = ... + // cmpTY ccX, r1, r2 + // bCC sinkMBB + // fallthrough --> copy0MBB + MachineBasicBlock *copy0MBB = new MachineBasicBlock(LLVM_BB); + MachineBasicBlock *sinkMBB = new MachineBasicBlock(LLVM_BB); + BuildMI(BB, X86::JNE, 1).addMBB(sinkMBB); + MachineFunction *F = BB->getParent(); + F->getBasicBlockList().insert(It, copy0MBB); + F->getBasicBlockList().insert(It, sinkMBB); + // Update machine-CFG edges + BB->addSuccessor(copy0MBB); + BB->addSuccessor(sinkMBB); + + // copy0MBB: + // %FalseValue = ... + // # fallthrough to sinkMBB + BB = copy0MBB; + // Update machine-CFG edges + BB->addSuccessor(sinkMBB); + + // sinkMBB: + // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ] + // ... + BB = sinkMBB; + BuildMI(BB, X86::PHI, 4, RDest).addReg(RFalse) + .addMBB(copy0MBB).addReg(RTrue).addMBB(thisMBB); return; } @@ -2285,6 +2326,13 @@ addConstantPoolReference(BuildMI(BB, X86::LEA32r, 4, Result), Tmp1); return Result; case ISD::ConstantFP: + if (X86ScalarSSE) { + assert(cast(N)->isExactlyValue(+0.0) && + "SSE only supports +0.0"); + Opc = (N.getValueType() == MVT::f32) ? X86::FLD0SS : X86::FLD0SD; + BuildMI(BB, Opc, 0, Result); + return Result; + } ContainsFPCode = true; Tmp1 = Result; // Intermediate Register if (cast(N)->getValue() < 0.0 || @@ -2969,14 +3017,8 @@ } case ISD::SELECT: - if (getRegPressure(N.getOperand(1)) > getRegPressure(N.getOperand(2))) { - Tmp2 = SelectExpr(N.getOperand(1)); - Tmp3 = SelectExpr(N.getOperand(2)); - } else { - Tmp3 = SelectExpr(N.getOperand(2)); - Tmp2 = SelectExpr(N.getOperand(1)); - } - EmitSelectCC(N.getOperand(0), N.getValueType(), Tmp2, Tmp3, Result); + EmitSelectCC(N.getOperand(0), N.getOperand(1), N.getOperand(2), + N.getValueType(), Result); return Result; case ISD::SDIV: Index: llvm/lib/Target/X86/X86InstrInfo.td diff -u llvm/lib/Target/X86/X86InstrInfo.td:1.130 llvm/lib/Target/X86/X86InstrInfo.td:1.131 --- llvm/lib/Target/X86/X86InstrInfo.td:1.130 Thu Jul 14 19:38:55 2005 +++ llvm/lib/Target/X86/X86InstrInfo.td Wed Aug 3 18:26:28 2005 @@ -1471,6 +1471,13 @@ def UCOMISSrm: I<0x2E, MRMSrcMem, (ops RXMM:$dst, f32mem:$src), "ucomiss {$src, $dst|$dst, $src}">, TB; +// Pseudo-instructions that map to fld0 to xorps/xorpd for sse. +// FIXME: remove when we can teach regalloc that xor reg, reg is ok. +def FLD0SS : I<0x57, MRMSrcReg, (ops RXMM:$dst), + "xorps $dst, $dst">, TB; +def FLD0SD : I<0x57, MRMSrcReg, (ops RXMM:$dst), + "xorpd $dst, $dst">, TB, OpSize; + let isTwoAddress = 1 in { let isCommutable = 1 in { def ADDSSrr : I<0x58, MRMSrcReg, (ops RXMM:$dst, RXMM:$src1, RXMM:$src), @@ -1489,6 +1496,10 @@ "orps {$src, $dst|$dst, $src}">, TB; def ORPDrr : I<0x56, MRMSrcReg, (ops RXMM:$dst, RXMM:$src1, RXMM:$src), "orpd {$src, $dst|$dst, $src}">, TB, OpSize; +def XORPSrr : I<0x57, MRMSrcReg, (ops RXMM:$dst, RXMM:$src1, RXMM:$src), + "xorps {$src, $dst|$dst, $src}">, TB; +def XORPDrr : I<0x57, MRMSrcReg, (ops RXMM:$dst, RXMM:$src1, RXMM:$src), + "xorpd {$src, $dst|$dst, $src}">, TB, OpSize; } def ANDNPSrr : I<0x55, MRMSrcReg, (ops RXMM:$dst, RXMM:$src1, RXMM:$src), "andnps {$src, $dst|$dst, $src}">, TB; From lattner at cs.uiuc.edu Wed Aug 3 18:30:19 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Wed, 3 Aug 2005 18:30:19 -0500 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp Message-ID: <200508032330.SAA18694@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Scalar: LoopStrengthReduce.cpp updated: 1.25 -> 1.26 --- Log message: improve debug output --- Diffs of the changes: (+9 -4) LoopStrengthReduce.cpp | 13 +++++++++---- 1 files changed, 9 insertions(+), 4 deletions(-) Index: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp diff -u llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.25 llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.26 --- llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.25 Wed Aug 3 17:51:21 2005 +++ llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp Wed Aug 3 18:30:08 2005 @@ -15,6 +15,7 @@ // //===----------------------------------------------------------------------===// +#define DEBUG_TYPE "loop-reduce" #include "llvm/Transforms/Scalar.h" #include "llvm/Constants.h" #include "llvm/Instructions.h" @@ -553,6 +554,8 @@ BasicBlock *LatchBlock = SomeLoopPHI->getIncomingBlock(SomeLoopPHI->getIncomingBlock(0) == Preheader); + DEBUG(std::cerr << "INSERTING IVs of STRIDE " << *Stride << ":\n"); + // FIXME: This loop needs increasing levels of intelligence. // STAGE 0: just emit everything as its own base. // STAGE 1: factor out common vars from bases, and try and push resulting @@ -565,7 +568,9 @@ std::sort(UsersToProcess.begin(), UsersToProcess.end()); while (!UsersToProcess.empty()) { SCEVHandle Base = UsersToProcess.front().first; - + + DEBUG(std::cerr << " INSERTING PHI with BASE = " << *Base << ":\n"); + // Create a new Phi for this base, and stick it in the loop header. const Type *ReplacedTy = Base->getType(); PHINode *NewPHI = new PHINode(ReplacedTy, "iv.", PhiInsertBefore); @@ -595,14 +600,14 @@ Rewriter.clear(); SCEVHandle NewValSCEV = SCEVAddExpr::get(SCEVUnknown::get(NewPHI), User.Imm); - Value *Replaced = UsersToProcess.front().second.OperandValToReplace; + Value *Replaced = User.OperandValToReplace; Value *newVal = Rewriter.expandCodeFor(NewValSCEV, User.Inst, Replaced->getType()); // Replace the use of the operand Value with the new Phi we just created. - DEBUG(std::cerr << "REPLACING: " << *Replaced << "IN: " << - *User.Inst << "WITH: "<< *newVal << '\n'); User.Inst->replaceUsesOfWith(Replaced, newVal); + DEBUG(std::cerr << " CHANGED: IMM =" << *User.Imm << " Inst = " + << *User.Inst); // Mark old value we replaced as possibly dead, so that it is elminated // if we just replaced the last use of that value. From lattner at cs.uiuc.edu Wed Aug 3 18:44:53 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Wed, 3 Aug 2005 18:44:53 -0500 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp Message-ID: <200508032344.SAA18785@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Scalar: LoopStrengthReduce.cpp updated: 1.26 -> 1.27 --- Log message: Teach loop-reduce to see into nested loops, to pull out immediate values pushed down by SCEV. In a nested loop case, this allows us to emit this: lis r3, ha16(L_A$non_lazy_ptr) lwz r3, lo16(L_A$non_lazy_ptr)(r3) add r2, r2, r3 li r3, 1 .LBB_foo_2: ; no_exit.1 lfd f0, 8(r2) ;; Uses offset of 8 instead of 0 stfd f0, 0(r2) addi r4, r3, 1 addi r2, r2, 8 cmpwi cr0, r3, 100 or r3, r4, r4 bne .LBB_foo_2 ; no_exit.1 instead of this: lis r3, ha16(L_A$non_lazy_ptr) lwz r3, lo16(L_A$non_lazy_ptr)(r3) add r2, r2, r3 addi r3, r3, 8 li r4, 1 .LBB_foo_2: ; no_exit.1 lfd f0, 0(r3) stfd f0, 0(r2) addi r5, r4, 1 addi r2, r2, 8 addi r3, r3, 8 cmpwi cr0, r4, 100 or r4, r5, r5 bne .LBB_foo_2 ; no_exit.1 --- Diffs of the changes: (+4 -2) LoopStrengthReduce.cpp | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-) Index: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp diff -u llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.26 llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.27 --- llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.26 Wed Aug 3 18:30:08 2005 +++ llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp Wed Aug 3 18:44:42 2005 @@ -483,8 +483,7 @@ if (isTargetConstant(Val)) return Val; - SCEVAddExpr *SAE = dyn_cast(Val); - if (SAE) { + if (SCEVAddExpr *SAE = dyn_cast(Val)) { unsigned i = 0; for (; i != SAE->getNumOperands(); ++i) if (isTargetConstant(SAE->getOperand(i))) { @@ -497,6 +496,9 @@ ImmVal = SCEVAddExpr::get(ImmVal, SAE->getOperand(i)); return ImmVal; } + } else if (SCEVAddRecExpr *SARE = dyn_cast(Val)) { + // Try to pull immediates out of the start value of nested addrec's. + return GetImmediateValues(SARE->getStart(), isAddress); } return SCEVUnknown::getIntegerSCEV(0, Val->getType()); From lattner at cs.uiuc.edu Wed Aug 3 19:14:22 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Wed, 3 Aug 2005 19:14:22 -0500 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp Message-ID: <200508040014.TAA19234@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Scalar: LoopStrengthReduce.cpp updated: 1.27 -> 1.28 --- Log message: When processing outer loops and we find uses of an IV in inner loops, make sure to handle the use, just don't recurse into it. This permits us to generate this code for a simple nested loop case: .LBB_foo_0: ; entry stwu r1, -48(r1) stw r29, 44(r1) stw r30, 40(r1) mflr r11 stw r11, 56(r1) lis r2, ha16(L_A$non_lazy_ptr) lwz r30, lo16(L_A$non_lazy_ptr)(r2) li r29, 1 .LBB_foo_1: ; no_exit.0 bl L_bar$stub li r2, 1 or r3, r30, r30 .LBB_foo_2: ; no_exit.1 lfd f0, 8(r3) stfd f0, 0(r3) addi r4, r2, 1 addi r3, r3, 8 cmpwi cr0, r2, 100 or r2, r4, r4 bne .LBB_foo_2 ; no_exit.1 .LBB_foo_3: ; loopexit.1 addi r30, r30, 800 addi r2, r29, 1 cmpwi cr0, r29, 100 or r29, r2, r2 bne .LBB_foo_1 ; no_exit.0 .LBB_foo_4: ; return lwz r11, 56(r1) mtlr r11 lwz r30, 40(r1) lwz r29, 44(r1) lwz r1, 0(r1) blr instead of this: _foo: .LBB_foo_0: ; entry stwu r1, -48(r1) stw r28, 44(r1) ;; uses an extra register. stw r29, 40(r1) stw r30, 36(r1) mflr r11 stw r11, 56(r1) li r30, 1 li r29, 0 or r28, r29, r29 .LBB_foo_1: ; no_exit.0 bl L_bar$stub mulli r2, r28, 800 ;; unstrength-reduced multiply lis r3, ha16(L_A$non_lazy_ptr) ;; loop invariant address computation lwz r3, lo16(L_A$non_lazy_ptr)(r3) add r2, r2, r3 mulli r4, r29, 800 ;; unstrength-reduced multiply addi r3, r3, 8 add r3, r4, r3 li r4, 1 .LBB_foo_2: ; no_exit.1 lfd f0, 0(r3) stfd f0, 0(r2) addi r5, r4, 1 addi r2, r2, 8 ;; multiple stride 8 IV's addi r3, r3, 8 cmpwi cr0, r4, 100 or r4, r5, r5 bne .LBB_foo_2 ; no_exit.1 .LBB_foo_3: ; loopexit.1 addi r28, r28, 1 ;;; Many IV's with stride 1 addi r29, r29, 1 addi r2, r30, 1 cmpwi cr0, r30, 100 or r30, r2, r2 bne .LBB_foo_1 ; no_exit.0 .LBB_foo_4: ; return lwz r11, 56(r1) mtlr r11 lwz r30, 36(r1) lwz r29, 40(r1) lwz r28, 44(r1) lwz r1, 0(r1) blr --- Diffs of the changes: (+9 -2) LoopStrengthReduce.cpp | 11 +++++++++-- 1 files changed, 9 insertions(+), 2 deletions(-) Index: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp diff -u llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.27 llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.28 --- llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.27 Wed Aug 3 18:44:42 2005 +++ llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp Wed Aug 3 19:14:11 2005 @@ -393,9 +393,16 @@ continue; // If this is an instruction defined in a nested loop, or outside this loop, - // don't mess with it. - if (LI->getLoopFor(User->getParent()) != L) + // don't recurse into it. + if (LI->getLoopFor(User->getParent()) != L) { + DEBUG(std::cerr << "FOUND USER in nested loop: " << *User + << " OF SCEV: " << *ISE << "\n"); + + // Okay, we found a user that we cannot reduce. Analyze the instruction + // and decide what to do with it. + IVUsesByStride[Step].addUser(Start, User, I); continue; + } // Next, see if this user is analyzable itself! if (!AddUsersIfInteresting(User, L)) { From lattner at cs.uiuc.edu Wed Aug 3 19:40:58 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Wed, 3 Aug 2005 19:40:58 -0500 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp Message-ID: <200508040040.TAA19486@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Scalar: LoopStrengthReduce.cpp updated: 1.28 -> 1.29 --- Log message: invert to if's to make the logic simpler --- Diffs of the changes: (+12 -15) LoopStrengthReduce.cpp | 27 ++++++++++++--------------- 1 files changed, 12 insertions(+), 15 deletions(-) Index: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp diff -u llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.28 llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.29 --- llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.28 Wed Aug 3 19:14:11 2005 +++ llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp Wed Aug 3 19:40:47 2005 @@ -405,21 +405,18 @@ } // Next, see if this user is analyzable itself! - if (!AddUsersIfInteresting(User, L)) { - if (GetElementPtrInst *GEP = dyn_cast(User)) { - // If this is a getelementptr instruction, figure out what linear - // expression of induction variable is actually being used. - // - if (AnalyzedGEPs.insert(GEP).second) // Not already analyzed? - AnalyzeGetElementPtrUsers(GEP, I, L); - } else { - DEBUG(std::cerr << "FOUND USER: " << *User - << " OF SCEV: " << *ISE << "\n"); - - // Okay, we found a user that we cannot reduce. Analyze the instruction - // and decide what to do with it. - IVUsesByStride[Step].addUser(Start, User, I); - } + if (GetElementPtrInst *GEP = dyn_cast(User)) { + // If this is a getelementptr instruction, figure out what linear + // expression of induction variable is actually being used. + if (AnalyzedGEPs.insert(GEP).second) // Not already analyzed? + AnalyzeGetElementPtrUsers(GEP, I, L); + } else if (!AddUsersIfInteresting(User, L)) { + DEBUG(std::cerr << "FOUND USER: " << *User + << " OF SCEV: " << *ISE << "\n"); + + // Okay, we found a user that we cannot reduce. Analyze the instruction + // and decide what to do with it. + IVUsesByStride[Step].addUser(Start, User, I); } } return true; From lattner at cs.uiuc.edu Wed Aug 3 20:18:59 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Wed, 3 Aug 2005 20:18:59 -0500 Subject: [llvm-commits] CVS: llvm/test/Regression/Transforms/LoopStrengthReduce/ops_after_indvar.ll Message-ID: <200508040118.UAA19754@zion.cs.uiuc.edu> Changes in directory llvm/test/Regression/Transforms/LoopStrengthReduce: ops_after_indvar.ll updated: 1.1 -> 1.2 --- Log message: this is not implemented by lsr yet --- Diffs of the changes: (+1 -0) ops_after_indvar.ll | 1 + 1 files changed, 1 insertion(+) Index: llvm/test/Regression/Transforms/LoopStrengthReduce/ops_after_indvar.ll diff -u llvm/test/Regression/Transforms/LoopStrengthReduce/ops_after_indvar.ll:1.1 llvm/test/Regression/Transforms/LoopStrengthReduce/ops_after_indvar.ll:1.2 --- llvm/test/Regression/Transforms/LoopStrengthReduce/ops_after_indvar.ll:1.1 Sun Mar 6 16:01:42 2005 +++ llvm/test/Regression/Transforms/LoopStrengthReduce/ops_after_indvar.ll Wed Aug 3 20:18:48 2005 @@ -2,6 +2,7 @@ ; gets reduced, making INDVAR dead. ; RUN: llvm-as < %s | opt -loop-reduce | llvm-dis | not grep INDVAR +; XFAIL: * declare bool %pred() declare int %getidx() From lattner at cs.uiuc.edu Wed Aug 3 20:19:24 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Wed, 3 Aug 2005 20:19:24 -0500 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp Message-ID: <200508040119.UAA19787@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Scalar: LoopStrengthReduce.cpp updated: 1.29 -> 1.30 --- Log message: refactor some code --- Diffs of the changes: (+45 -34) LoopStrengthReduce.cpp | 79 +++++++++++++++++++++++++++---------------------- 1 files changed, 45 insertions(+), 34 deletions(-) Index: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp diff -u llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.29 llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.30 --- llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.29 Wed Aug 3 19:40:47 2005 +++ llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp Wed Aug 3 20:19:13 2005 @@ -96,10 +96,10 @@ /// are interested in. The key of the map is the stride of the access. std::map IVUsesByStride; - /// CastedBasePointers - As we need to lower getelementptr instructions, we - /// cast the pointer input to uintptr_t. This keeps track of the casted - /// values for the pointers we have processed so far. - std::map CastedBasePointers; + /// CastedValues - As we need to cast values to uintptr_t, this keeps track + /// of the casted version of each value. This is accessed by + /// getCastedVersionOf. + std::map CastedPointers; /// DeadInsts - Keep track of instructions we may have made dead, so that /// we can remove them after we are done working. @@ -119,6 +119,8 @@ for (LoopInfo::iterator I = LI->begin(), E = LI->end(); I != E; ++I) runOnLoop(*I); + + CastedPointers.clear(); return Changed; } @@ -130,7 +132,11 @@ AU.addRequired(); AU.addRequired(); } - private: + + /// getCastedVersionOf - Return the specified value casted to uintptr_t. + /// + Value *getCastedVersionOf(Value *V); +private: void runOnLoop(Loop *L); bool AddUsersIfInteresting(Instruction *I, Loop *L); void AnalyzeGetElementPtrUsers(GetElementPtrInst *GEP, Instruction *I, @@ -153,6 +159,37 @@ return new LoopStrengthReduce(MaxTargetAMSize); } +/// getCastedVersionOf - Return the specified value casted to uintptr_t. +/// +Value *LoopStrengthReduce::getCastedVersionOf(Value *V) { + if (V->getType() == UIntPtrTy) return V; + if (Constant *CB = dyn_cast(V)) + return ConstantExpr::getCast(CB, UIntPtrTy); + + Value *&New = CastedPointers[V]; + if (New) return New; + + BasicBlock::iterator InsertPt; + if (Argument *Arg = dyn_cast(V)) { + // Insert into the entry of the function, after any allocas. + InsertPt = Arg->getParent()->begin()->begin(); + while (isa(InsertPt)) ++InsertPt; + } else { + if (InvokeInst *II = dyn_cast(V)) { + InsertPt = II->getNormalDest()->begin(); + } else { + InsertPt = cast(V); + ++InsertPt; + } + + // Do not insert casts into the middle of PHI node blocks. + while (isa(InsertPt)) ++InsertPt; + } + + return New = new CastInst(V, UIntPtrTy, V->getName(), InsertPt); +} + + /// DeleteTriviallyDeadInstructions - If any of the instructions is the /// specified set are trivially dead, delete them and see if this makes any of /// their operands subsequently dead. @@ -218,6 +255,7 @@ return Result; } + /// AnalyzeGetElementPtrUsers - Analyze all of the users of the specified /// getelementptr instruction, adding them to the IVUsesByStride table. Note /// that we only want to analyze a getelementptr instruction once, and it can @@ -233,33 +271,7 @@ // Build up the base expression. Insert an LLVM cast of the pointer to // uintptr_t first. - Value *BasePtr; - if (Constant *CB = dyn_cast(GEP->getOperand(0))) - BasePtr = ConstantExpr::getCast(CB, UIntPtrTy); - else { - Value *&BP = CastedBasePointers[GEP->getOperand(0)]; - if (BP == 0) { - BasicBlock::iterator InsertPt; - if (isa(GEP->getOperand(0))) { - InsertPt = GEP->getParent()->getParent()->begin()->begin(); - } else { - InsertPt = cast(GEP->getOperand(0)); - if (InvokeInst *II = dyn_cast(GEP->getOperand(0))) - InsertPt = II->getNormalDest()->begin(); - else - ++InsertPt; - } - - // Do not insert casts into the middle of PHI node blocks. - while (isa(InsertPt)) ++InsertPt; - - BP = new CastInst(GEP->getOperand(0), UIntPtrTy, - GEP->getOperand(0)->getName(), InsertPt); - } - BasePtr = BP; - } - - SCEVHandle Base = SCEVUnknown::get(BasePtr); + SCEVHandle Base = SCEVUnknown::get(getCastedVersionOf(GEP->getOperand(0))); gep_type_iterator GTI = gep_type_begin(GEP); unsigned i = 1; @@ -316,7 +328,7 @@ // FIXME: If the base is not loop invariant, we currently cannot emit this. if (!Base->isLoopInvariant(L)) { - DEBUG(std::cerr << "IGNORING GEP due to non-invaiant base: " + DEBUG(std::cerr << "IGNORING GEP due to non-invariant base: " << *Base << "\n"); return; } @@ -703,6 +715,5 @@ } IVUsesByStride.clear(); - CastedBasePointers.clear(); return; } From natebegeman at mac.com Thu Aug 4 02:12:21 2005 From: natebegeman at mac.com (Nate Begeman) Date: Thu, 4 Aug 2005 02:12:21 -0500 Subject: [llvm-commits] CVS: llvm/lib/Target/X86/X86Subtarget.cpp X86Subtarget.h Message-ID: <200508040712.CAA02021@zion.cs.uiuc.edu> Changes in directory llvm/lib/Target/X86: X86Subtarget.cpp updated: 1.4 -> 1.5 X86Subtarget.h updated: 1.3 -> 1.4 --- Log message: Add Subtarget support to PowerPC. Next up, using it. --- Diffs of the changes: (+2 -2) X86Subtarget.cpp | 2 +- X86Subtarget.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) Index: llvm/lib/Target/X86/X86Subtarget.cpp diff -u llvm/lib/Target/X86/X86Subtarget.cpp:1.4 llvm/lib/Target/X86/X86Subtarget.cpp:1.5 --- llvm/lib/Target/X86/X86Subtarget.cpp:1.4 Wed Jul 27 01:12:34 2005 +++ llvm/lib/Target/X86/X86Subtarget.cpp Thu Aug 4 02:12:09 2005 @@ -1,4 +1,4 @@ -//===- X86Subtarget.cpp - X86 Instruction Information -----------*- C++ -*-===// +//===-- X86Subtarget.cpp - X86 Subtarget Information ------------*- C++ -*-===// // // The LLVM Compiler Infrastructure // Index: llvm/lib/Target/X86/X86Subtarget.h diff -u llvm/lib/Target/X86/X86Subtarget.h:1.3 llvm/lib/Target/X86/X86Subtarget.h:1.4 --- llvm/lib/Target/X86/X86Subtarget.h:1.3 Wed Jul 27 00:53:44 2005 +++ llvm/lib/Target/X86/X86Subtarget.h Thu Aug 4 02:12:09 2005 @@ -1,4 +1,4 @@ -//=====-- X86Subtarget.h - Define TargetMachine for the X86 ---*- C++ -*--====// +//=====---- X86Subtarget.h - Define Subtarget for the X86 -----*- C++ -*--====// // // The LLVM Compiler Infrastructure // From natebegeman at mac.com Thu Aug 4 02:12:21 2005 From: natebegeman at mac.com (Nate Begeman) Date: Thu, 4 Aug 2005 02:12:21 -0500 Subject: [llvm-commits] CVS: llvm/lib/Target/PowerPC/PowerPCSubtarget.cpp PowerPCSubtarget.h PowerPCTargetMachine.cpp PowerPCTargetMachine.h Message-ID: <200508040712.CAA02022@zion.cs.uiuc.edu> Changes in directory llvm/lib/Target/PowerPC: PowerPCSubtarget.cpp added (r1.1) PowerPCSubtarget.h added (r1.1) PowerPCTargetMachine.cpp updated: 1.57 -> 1.58 PowerPCTargetMachine.h updated: 1.13 -> 1.14 --- Log message: Add Subtarget support to PowerPC. Next up, using it. --- Diffs of the changes: (+114 -8) PowerPCSubtarget.cpp | 54 +++++++++++++++++++++++++++++++++++++++++++++++ PowerPCSubtarget.h | 48 +++++++++++++++++++++++++++++++++++++++++ PowerPCTargetMachine.cpp | 8 +++--- PowerPCTargetMachine.h | 12 ++++++---- 4 files changed, 114 insertions(+), 8 deletions(-) Index: llvm/lib/Target/PowerPC/PowerPCSubtarget.cpp diff -c /dev/null llvm/lib/Target/PowerPC/PowerPCSubtarget.cpp:1.1 *** /dev/null Thu Aug 4 02:12:19 2005 --- llvm/lib/Target/PowerPC/PowerPCSubtarget.cpp Thu Aug 4 02:12:08 2005 *************** *** 0 **** --- 1,54 ---- + //===- PowerPCSubtarget.cpp - PPC Subtarget Information ---------*- C++ -*-===// + // + // The LLVM Compiler Infrastructure + // + // This file was developed by Nate Begeman and is distributed under the + // University of Illinois Open Source License. See LICENSE.TXT for details. + // + //===----------------------------------------------------------------------===// + // + // This file implements the PPC specific subclass of TargetSubtarget. + // + //===----------------------------------------------------------------------===// + + #include "PowerPCSubtarget.h" + #include "llvm/Module.h" + + #if defined(__APPLE__) + #include + #include + #include + #include + + static boolean_t IsGP() { + host_basic_info_data_t hostInfo; + mach_msg_type_number_t infoCount; + + infoCount = HOST_BASIC_INFO_COUNT; + host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo, + &infoCount); + + return ((hostInfo.cpu_type == CPU_TYPE_POWERPC) && + (hostInfo.cpu_subtype == CPU_SUBTYPE_POWERPC_970)); + } + #endif + + using namespace llvm; + + PPCSubtarget::PPCSubtarget(const Module &M) + : TargetSubtarget(), stackAlignment(16), isGigaProcessor(false), isAIX(false), + isDarwin(false) { + // Set the boolean corresponding to the current target triple, or the default + // if one cannot be determined, to true. + const std::string& TT = M.getTargetTriple(); + if (TT.length() > 5) { + isDarwin = TT.find("darwin") != std::string::npos; + } else if (TT.empty()) { + #if defined(_POWER) + isAIX = true; + #elif defined(__APPLE__) + isDarwin = true; + isGigaProcessor = IsGP(); + #endif + } + } Index: llvm/lib/Target/PowerPC/PowerPCSubtarget.h diff -c /dev/null llvm/lib/Target/PowerPC/PowerPCSubtarget.h:1.1 *** /dev/null Thu Aug 4 02:12:21 2005 --- llvm/lib/Target/PowerPC/PowerPCSubtarget.h Thu Aug 4 02:12:08 2005 *************** *** 0 **** --- 1,48 ---- + //=====-- PowerPCSubtarget.h - Define Subtarget for the PPC ---*- C++ -*--====// + // + // The LLVM Compiler Infrastructure + // + // This file was developed by Nate Begeman and is distributed under the + // University of Illinois Open Source License. See LICENSE.TXT for details. + // + //===----------------------------------------------------------------------===// + // + // This file declares the X86 specific subclass of TargetSubtarget. + // + //===----------------------------------------------------------------------===// + + #ifndef POWERPCSUBTARGET_H + #define POWERPCSUBTARGET_H + + #include "llvm/Target/TargetSubtarget.h" + + namespace llvm { + class Module; + + class PPCSubtarget : public TargetSubtarget { + protected: + /// stackAlignment - The minimum alignment known to hold of the stack frame on + /// entry to the function and which must be maintained by every function. + unsigned stackAlignment; + + /// Used by the ISel to turn in optimizations for POWER4-derived architectures + bool isGigaProcessor; + bool isAIX; + bool isDarwin; + public: + /// This constructor initializes the data members to match that + /// of the specified module. + /// + PPCSubtarget(const Module &M); + + /// getStackAlignment - Returns the minimum alignment known to hold of the + /// stack frame on entry to the function and which must be maintained by every + /// function for this subtarget. + unsigned getStackAlignment() const { return stackAlignment; } + + bool IsAIX() const { return isAIX; } + bool IsDarwin() const { return isDarwin; } + }; + } // End llvm namespace + + #endif Index: llvm/lib/Target/PowerPC/PowerPCTargetMachine.cpp diff -u llvm/lib/Target/PowerPC/PowerPCTargetMachine.cpp:1.57 llvm/lib/Target/PowerPC/PowerPCTargetMachine.cpp:1.58 --- llvm/lib/Target/PowerPC/PowerPCTargetMachine.cpp:1.57 Wed Jul 27 01:12:33 2005 +++ llvm/lib/Target/PowerPC/PowerPCTargetMachine.cpp Thu Aug 4 02:12:08 2005 @@ -59,10 +59,10 @@ PowerPCTargetMachine::PowerPCTargetMachine(const std::string &name, IntrinsicLowering *IL, + const Module &M, const TargetData &TD, const PowerPCFrameInfo &TFI) - : TargetMachine(name, IL, TD), FrameInfo(TFI) -{} +: TargetMachine(name, IL, TD), FrameInfo(TFI), Subtarget(M) {} unsigned PPC32TargetMachine::getJITMatchQuality() { #if defined(__POWERPC__) || defined (__ppc__) || defined(_POWER) @@ -177,14 +177,14 @@ /// PowerPCTargetMachine ctor - Create an ILP32 architecture model /// PPC32TargetMachine::PPC32TargetMachine(const Module &M, IntrinsicLowering *IL) - : PowerPCTargetMachine(PPC32ID, IL, + : PowerPCTargetMachine(PPC32ID, IL, M, TargetData(PPC32ID,false,4,4,4,4,4,4,2,1,1), PowerPCFrameInfo(*this, false)), JITInfo(*this) {} /// PPC64TargetMachine ctor - Create a LP64 architecture model /// PPC64TargetMachine::PPC64TargetMachine(const Module &M, IntrinsicLowering *IL) - : PowerPCTargetMachine(PPC64ID, IL, + : PowerPCTargetMachine(PPC64ID, IL, M, TargetData(PPC64ID,false,8,4,4,4,4,4,2,1,1), PowerPCFrameInfo(*this, true)) {} Index: llvm/lib/Target/PowerPC/PowerPCTargetMachine.h diff -u llvm/lib/Target/PowerPC/PowerPCTargetMachine.h:1.13 llvm/lib/Target/PowerPC/PowerPCTargetMachine.h:1.14 --- llvm/lib/Target/PowerPC/PowerPCTargetMachine.h:1.13 Fri Jun 24 21:48:37 2005 +++ llvm/lib/Target/PowerPC/PowerPCTargetMachine.h Thu Aug 4 02:12:08 2005 @@ -14,9 +14,11 @@ #ifndef POWERPC_TARGETMACHINE_H #define POWERPC_TARGETMACHINE_H -#include "PowerPCFrameInfo.h" #include "llvm/Target/TargetMachine.h" +#include "llvm/Target/TargetFrameInfo.h" #include "llvm/PassManager.h" +#include "PowerPCFrameInfo.h" +#include "PowerPCSubtarget.h" namespace llvm { @@ -24,13 +26,15 @@ class IntrinsicLowering; class PowerPCTargetMachine : public TargetMachine { - PowerPCFrameInfo FrameInfo; - + PowerPCFrameInfo FrameInfo; + PPCSubtarget Subtarget; protected: PowerPCTargetMachine(const std::string &name, IntrinsicLowering *IL, - const TargetData &TD, const PowerPCFrameInfo &TFI); + const Module &M, const TargetData &TD, + const PowerPCFrameInfo &TFI); public: virtual const TargetFrameInfo *getFrameInfo() const { return &FrameInfo; } + virtual const TargetSubtarget *getSubtargetImpl() const{ return &Subtarget; } virtual bool addPassesToEmitFile(PassManager &PM, std::ostream &Out, CodeGenFileType FileType); From alenhar2 at cs.uiuc.edu Thu Aug 4 07:43:03 2005 From: alenhar2 at cs.uiuc.edu (Andrew Lenharth) Date: Thu, 4 Aug 2005 07:43:03 -0500 Subject: [llvm-commits] CVS: llvm-test/Makefile.programs Message-ID: <200508041243.HAA32452@zion.cs.uiuc.edu> Changes in directory llvm-test: Makefile.programs updated: 1.158 -> 1.159 --- Log message: try some different llc-beta flags for alpha for a while --- Diffs of the changes: (+2 -2) Makefile.programs | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) Index: llvm-test/Makefile.programs diff -u llvm-test/Makefile.programs:1.158 llvm-test/Makefile.programs:1.159 --- llvm-test/Makefile.programs:1.158 Wed Jul 27 01:23:17 2005 +++ llvm-test/Makefile.programs Thu Aug 4 07:42:52 2005 @@ -190,8 +190,8 @@ LLCBETAOPTION := -enable-gpopt endif ifeq ($(ARCH),Alpha) -LLCBETAOPTION := -enable-alpha-intfpdiv -enable-alpha-ftoi -#-enable-lsr-for-alpha +LLCBETAOPTION := -enable-alpha-ftoi -enable-lsr-for-alpha +#-enable-alpha-intfpdiv endif ifeq ($(ARCH),x86) LLCBETAOPTION := -enable-x86-fastcc From brukman at cs.uiuc.edu Thu Aug 4 09:17:00 2005 From: brukman at cs.uiuc.edu (Misha Brukman) Date: Thu, 4 Aug 2005 09:17:00 -0500 Subject: [llvm-commits] CVS: llvm/lib/Analysis/CFGPrinter.cpp Message-ID: <200508041417.JAA02936@zion.cs.uiuc.edu> Changes in directory llvm/lib/Analysis: CFGPrinter.cpp updated: 1.13 -> 1.14 --- Log message: * Unbreak optimized build (noticed by Eric van Riet Paap) * Comment #endif clauses for readability --- Diffs of the changes: (+5 -3) CFGPrinter.cpp | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-) Index: llvm/lib/Analysis/CFGPrinter.cpp diff -u llvm/lib/Analysis/CFGPrinter.cpp:1.13 llvm/lib/Analysis/CFGPrinter.cpp:1.14 --- llvm/lib/Analysis/CFGPrinter.cpp:1.13 Wed Aug 3 12:55:05 2005 +++ llvm/lib/Analysis/CFGPrinter.cpp Thu Aug 4 09:16:48 2005 @@ -160,7 +160,7 @@ system(("rm " + Filename).c_str()); return; } -#endif +#endif // HAVE_GRAPHVIZ #ifdef HAVE_GV std::cerr << "Running 'dot' program... " << std::flush; @@ -173,12 +173,14 @@ } system(("rm " + Filename + " /tmp/cfg.tempgraph.ps").c_str()); return; -#endif -#endif +#endif // HAVE_GV +#endif // NDEBUG std::cerr << "Function::viewCFG is only available in debug builds on " << "systems with Graphviz or gv!\n"; +#ifndef NDEBUG system(("rm " + Filename).c_str()); +#endif } /// viewCFGOnly - This function is meant for use from the debugger. It works From brukman at cs.uiuc.edu Thu Aug 4 09:22:52 2005 From: brukman at cs.uiuc.edu (Misha Brukman) Date: Thu, 4 Aug 2005 09:22:52 -0500 Subject: [llvm-commits] CVS: llvm/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp Message-ID: <200508041422.JAA11195@zion.cs.uiuc.edu> Changes in directory llvm/lib/CodeGen/SelectionDAG: SelectionDAGPrinter.cpp updated: 1.17 -> 1.18 --- Log message: * Unbreak release build * Add comments to #endif pragmas for readability --- Diffs of the changes: (+6 -3) SelectionDAGPrinter.cpp | 9 ++++++--- 1 files changed, 6 insertions(+), 3 deletions(-) Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp diff -u llvm/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp:1.17 llvm/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp:1.18 --- llvm/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp:1.17 Wed Aug 3 15:31:37 2005 +++ llvm/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp Thu Aug 4 09:22:41 2005 @@ -127,7 +127,7 @@ system(("rm " + Filename).c_str()); return; } -#endif +#endif // HAVE_GRAPHVIZ #ifdef HAVE_GV std::cerr << "Running 'dot' program... " << std::flush; @@ -140,9 +140,12 @@ } system(("rm " + Filename + " /tmp/dag.tempgraph.ps").c_str()); return; -#endif -#endif +#endif // HAVE_GV +#endif // NDEBUG std::cerr << "SelectionDAG::viewGraph is only available in debug builds on " << "systems with Graphviz or gv!\n"; + +#ifndef NDEBUG system(("rm " + Filename).c_str()); +#endif } From alenhar2 at cs.uiuc.edu Thu Aug 4 10:32:47 2005 From: alenhar2 at cs.uiuc.edu (Andrew Lenharth) Date: Thu, 4 Aug 2005 10:32:47 -0500 Subject: [llvm-commits] CVS: llvm/lib/Target/Alpha/AlphaJITInfo.cpp AlphaCodeEmitter.cpp Message-ID: <200508041532.KAA15827@zion.cs.uiuc.edu> Changes in directory llvm/lib/Target/Alpha: AlphaJITInfo.cpp updated: 1.6 -> 1.7 AlphaCodeEmitter.cpp updated: 1.5 -> 1.6 --- Log message: No, IDEFs shouldn't be JITed --- Diffs of the changes: (+6 -3) AlphaCodeEmitter.cpp | 7 +++++-- AlphaJITInfo.cpp | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) Index: llvm/lib/Target/Alpha/AlphaJITInfo.cpp diff -u llvm/lib/Target/Alpha/AlphaJITInfo.cpp:1.6 llvm/lib/Target/Alpha/AlphaJITInfo.cpp:1.7 --- llvm/lib/Target/Alpha/AlphaJITInfo.cpp:1.6 Sat Jul 30 13:33:25 2005 +++ llvm/lib/Target/Alpha/AlphaJITInfo.cpp Thu Aug 4 10:32:36 2005 @@ -64,7 +64,7 @@ for (int x = 1; x <= 8; ++x) { AtI[2*x - 1] = BUILD_SLLi(27,27,8); unsigned d = (Fn >> (64 - 8 * x)) & 0x00FF; - DEBUG(std::cerr << "outputing " << hex << d << dec << "\n"); + // DEBUG(std::cerr << "outputing " << hex << d << dec << "\n"); AtI[2*x] = BUILD_ORi(27, 27, d); } AtI[17] = BUILD_JMP(31,27,0); //jump, preserving ra, and setting pv Index: llvm/lib/Target/Alpha/AlphaCodeEmitter.cpp diff -u llvm/lib/Target/Alpha/AlphaCodeEmitter.cpp:1.5 llvm/lib/Target/Alpha/AlphaCodeEmitter.cpp:1.6 --- llvm/lib/Target/Alpha/AlphaCodeEmitter.cpp:1.5 Thu Jul 28 13:14:47 2005 +++ llvm/lib/Target/Alpha/AlphaCodeEmitter.cpp Thu Aug 4 10:32:36 2005 @@ -89,9 +89,11 @@ for (unsigned i = 0, e = BBRefs.size(); i != e; ++i) { unsigned* Location = (unsigned*)BasicBlockAddrs[BBRefs[i].first]; unsigned* Ref = (unsigned*)BBRefs[i].second; - intptr_t BranchTargetDisp = (((unsigned char*)Location - (unsigned char*)Ref) >> 2) - 1; + intptr_t BranchTargetDisp = + (((unsigned char*)Location - (unsigned char*)Ref) >> 2) - 1; DEBUG(std::cerr << "Fixup @ " << (void*)Ref << " to " << (void*)Location - << " Disp " << BranchTargetDisp << " using " << (BranchTargetDisp & ((1 << 22)-1)) << "\n"); + << " Disp " << BranchTargetDisp + << " using " << (BranchTargetDisp & ((1 << 22)-1)) << "\n"); *Ref |= (BranchTargetDisp & ((1 << 21)-1)); } BBRefs.clear(); @@ -115,6 +117,7 @@ case Alpha::ALTENT: case Alpha::PCLABEL: case Alpha::MEMLABEL: + case Alpha::IDEF: break; //skip these } } From lattner at cs.uiuc.edu Thu Aug 4 12:40:41 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu, 4 Aug 2005 12:40:41 -0500 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp Message-ID: <200508041740.MAA02256@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Scalar: LoopStrengthReduce.cpp updated: 1.30 -> 1.31 --- Log message: Refactor this code substantially with the following improvements: 1. We only analyze instructions once, guaranteed 2. AnalyzeGetElementPtrUsers has been ripped apart and replaced with something much simpler. The next step is to handle expressions that are not all indvar+loop-invariant values (e.g. handling indvar+loopvariant). --- Diffs of the changes: (+38 -138) LoopStrengthReduce.cpp | 176 ++++++++++--------------------------------------- 1 files changed, 38 insertions(+), 138 deletions(-) Index: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp diff -u llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.30 llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.31 --- llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.30 Wed Aug 3 20:19:13 2005 +++ llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp Thu Aug 4 12:40:30 2005 @@ -138,9 +138,10 @@ Value *getCastedVersionOf(Value *V); private: void runOnLoop(Loop *L); - bool AddUsersIfInteresting(Instruction *I, Loop *L); - void AnalyzeGetElementPtrUsers(GetElementPtrInst *GEP, Instruction *I, - Loop *L); + bool AddUsersIfInteresting(Instruction *I, Loop *L, + std::set &Processed); + SCEVHandle GetExpressionSCEV(Instruction *E, Loop *L); + void StrengthReduceStridedIVUsers(Value *Stride, IVUsersOfOneStride &Uses, Loop *L, bool isOnlyStride); @@ -234,48 +235,24 @@ return false; } - -/// GetAdjustedIndex - Adjust the specified GEP sequential type index to match -/// the size of the pointer type, and scale it by the type size. -static SCEVHandle GetAdjustedIndex(const SCEVHandle &Idx, uint64_t TySize, - const Type *UIntPtrTy) { - SCEVHandle Result = Idx; - if (Result->getType()->getUnsignedVersion() != UIntPtrTy) { - if (UIntPtrTy->getPrimitiveSize() < Result->getType()->getPrimitiveSize()) - Result = SCEVTruncateExpr::get(Result, UIntPtrTy); - else - Result = SCEVZeroExtendExpr::get(Result, UIntPtrTy); - } - - // This index is scaled by the type size being indexed. - if (TySize != 1) - Result = SCEVMulExpr::get(Result, - SCEVConstant::get(ConstantUInt::get(UIntPtrTy, - TySize))); - return Result; -} - - -/// AnalyzeGetElementPtrUsers - Analyze all of the users of the specified -/// getelementptr instruction, adding them to the IVUsesByStride table. Note -/// that we only want to analyze a getelementptr instruction once, and it can -/// have multiple operands that are uses of the indvar (e.g. A[i][i]). Because -/// of this, we only process a GEP instruction if its first recurrent operand is -/// "op", otherwise we will either have already processed it or we will sometime -/// later. -void LoopStrengthReduce::AnalyzeGetElementPtrUsers(GetElementPtrInst *GEP, - Instruction *Op, Loop *L) { +/// GetExpressionSCEV - Compute and return the SCEV for the specified +/// instruction. +SCEVHandle LoopStrengthReduce::GetExpressionSCEV(Instruction *Exp, Loop *L) { + GetElementPtrInst *GEP = dyn_cast(Exp); + if (!GEP) + return SE->getSCEV(Exp); + // Analyze all of the subscripts of this getelementptr instruction, looking // for uses that are determined by the trip count of L. First, skip all // operands the are not dependent on the IV. // Build up the base expression. Insert an LLVM cast of the pointer to // uintptr_t first. - SCEVHandle Base = SCEVUnknown::get(getCastedVersionOf(GEP->getOperand(0))); + SCEVHandle GEPVal = SCEVUnknown::get(getCastedVersionOf(GEP->getOperand(0))); gep_type_iterator GTI = gep_type_begin(GEP); - unsigned i = 1; - for (; GEP->getOperand(i) != Op; ++i, ++GTI) { + + for (unsigned i = 1, e = GEP->getNumOperands(); i != e; ++i, ++GTI) { // If this is a use of a recurrence that we can analyze, and it comes before // Op does in the GEP operand list, we will handle this when we process this // operand. @@ -283,104 +260,37 @@ const StructLayout *SL = TD->getStructLayout(STy); unsigned Idx = cast(GEP->getOperand(i))->getValue(); uint64_t Offset = SL->MemberOffsets[Idx]; - Base = SCEVAddExpr::get(Base, SCEVUnknown::getIntegerSCEV(Offset, - UIntPtrTy)); + GEPVal = SCEVAddExpr::get(GEPVal, + SCEVUnknown::getIntegerSCEV(Offset, UIntPtrTy)); } else { - SCEVHandle Idx = SE->getSCEV(GEP->getOperand(i)); - - // If this operand is reducible, and it's not the one we are looking at - // currently, do not process the GEP at this time. - if (CanReduceSCEV(Idx, L)) - return; - Base = SCEVAddExpr::get(Base, GetAdjustedIndex(Idx, - TD->getTypeSize(GTI.getIndexedType()), UIntPtrTy)); + SCEVHandle Idx = SE->getSCEV(getCastedVersionOf(GEP->getOperand(i))); + uint64_t TypeSize = TD->getTypeSize(GTI.getIndexedType()); + if (TypeSize != 1) + Idx = SCEVMulExpr::get(Idx, + SCEVConstant::get(ConstantUInt::get(UIntPtrTy, + TypeSize))); + GEPVal = SCEVAddExpr::get(GEPVal, Idx); } } - // Get the index, convert it to intptr_t. - SCEVHandle GEPIndexExpr = - GetAdjustedIndex(SE->getSCEV(Op), TD->getTypeSize(GTI.getIndexedType()), - UIntPtrTy); - - // Process all remaining subscripts in the GEP instruction. - for (++i, ++GTI; i != GEP->getNumOperands(); ++i, ++GTI) - if (const StructType *STy = dyn_cast(*GTI)) { - const StructLayout *SL = TD->getStructLayout(STy); - unsigned Idx = cast(GEP->getOperand(i))->getValue(); - uint64_t Offset = SL->MemberOffsets[Idx]; - Base = SCEVAddExpr::get(Base, SCEVUnknown::getIntegerSCEV(Offset, - UIntPtrTy)); - } else { - SCEVHandle Idx = SE->getSCEV(GEP->getOperand(i)); - if (CanReduceSCEV(Idx, L)) { // Another IV subscript - GEPIndexExpr = SCEVAddExpr::get(GEPIndexExpr, - GetAdjustedIndex(Idx, TD->getTypeSize(GTI.getIndexedType()), - UIntPtrTy)); - assert(CanReduceSCEV(GEPIndexExpr, L) && - "Cannot reduce the sum of two reducible SCEV's??"); - } else { - Base = SCEVAddExpr::get(Base, GetAdjustedIndex(Idx, - TD->getTypeSize(GTI.getIndexedType()), UIntPtrTy)); - } - } - - assert(CanReduceSCEV(GEPIndexExpr, L) && "Non reducible idx??"); - - // FIXME: If the base is not loop invariant, we currently cannot emit this. - if (!Base->isLoopInvariant(L)) { - DEBUG(std::cerr << "IGNORING GEP due to non-invariant base: " - << *Base << "\n"); - return; - } - - Base = SCEVAddExpr::get(Base, cast(GEPIndexExpr)->getStart()); - SCEVHandle Stride = cast(GEPIndexExpr)->getOperand(1); - - DEBUG(std::cerr << "GEP BASE : " << *Base << "\n"); - DEBUG(std::cerr << "GEP STRIDE: " << *Stride << "\n"); - - Value *Step = 0; // Step of ISE. - if (SCEVConstant *SC = dyn_cast(Stride)) - /// Always get the step value as an unsigned value. - Step = ConstantExpr::getCast(SC->getValue(), - SC->getValue()->getType()->getUnsignedVersion()); - else - Step = cast(Stride)->getValue(); - assert(Step->getType()->isUnsigned() && "Bad step value!"); - - - // Now that we know the base and stride contributed by the GEP instruction, - // process all users. - for (Value::use_iterator UI = GEP->use_begin(), E = GEP->use_end(); - UI != E; ++UI) { - Instruction *User = cast(*UI); - - // Do not infinitely recurse on PHI nodes. - if (isa(User) && User->getParent() == L->getHeader()) - continue; - - // If this is an instruction defined in a nested loop, or outside this loop, - // don't mess with it. - if (LI->getLoopFor(User->getParent()) != L) - continue; - - DEBUG(std::cerr << "FOUND USER: " << *User - << " OF STRIDE: " << *Step << " BASE = " << *Base << "\n"); - - // Okay, we found a user that we cannot reduce. Analyze the instruction - // and decide what to do with it. - IVUsesByStride[Step].addUser(Base, User, GEP); - } + //assert(CanReduceSCEV(GEPVal, L) && "Cannot reduce this use of IV?"); + return GEPVal; } /// AddUsersIfInteresting - Inspect the specified instruction. If it is a /// reducible SCEV, recursively add its users to the IVUsesByStride set and /// return true. Otherwise, return false. -bool LoopStrengthReduce::AddUsersIfInteresting(Instruction *I, Loop *L) { +bool LoopStrengthReduce::AddUsersIfInteresting(Instruction *I, Loop *L, + std::set &Processed) { if (I->getType() == Type::VoidTy) return false; - SCEVHandle ISE = SE->getSCEV(I); - if (!CanReduceSCEV(ISE, L)) return false; - + if (!Processed.insert(I).second) + return true; // Instruction already handled. + + SCEVHandle ISE = GetExpressionSCEV(I, L); + if (!CanReduceSCEV(ISE, L)) + return false; // Non-analyzable expression, e.g. a rem instr. + + // NOT SAFE with generalized EXPRS SCEVAddRecExpr *AR = cast(ISE); SCEVHandle Start = AR->getStart(); @@ -395,8 +305,6 @@ Step = cast(AR->getOperand(1))->getValue(); assert(Step->getType()->isUnsigned() && "Bad step value!"); - std::set AnalyzedGEPs; - for (Value::use_iterator UI = I->use_begin(), E = I->use_end(); UI != E;++UI){ Instruction *User = cast(*UI); @@ -413,16 +321,7 @@ // Okay, we found a user that we cannot reduce. Analyze the instruction // and decide what to do with it. IVUsesByStride[Step].addUser(Start, User, I); - continue; - } - - // Next, see if this user is analyzable itself! - if (GetElementPtrInst *GEP = dyn_cast(User)) { - // If this is a getelementptr instruction, figure out what linear - // expression of induction variable is actually being used. - if (AnalyzedGEPs.insert(GEP).second) // Not already analyzed? - AnalyzeGetElementPtrUsers(GEP, I, L); - } else if (!AddUsersIfInteresting(User, L)) { + } else if (!AddUsersIfInteresting(User, L, Processed)) { DEBUG(std::cerr << "FOUND USER: " << *User << " OF SCEV: " << *ISE << "\n"); @@ -655,8 +554,9 @@ // Next, find all uses of induction variables in this loop, and catagorize // them by stride. Start by finding all of the PHI nodes in the header for // this loop. If they are induction variables, inspect their uses. + std::set Processed; // Don't reprocess instructions. for (BasicBlock::iterator I = L->getHeader()->begin(); isa(I); ++I) - AddUsersIfInteresting(I, L); + AddUsersIfInteresting(I, L, Processed); // If we have nothing to do, return. //if (IVUsesByStride.empty()) return; From natebegeman at mac.com Thu Aug 4 13:14:08 2005 From: natebegeman at mac.com (Nate Begeman) Date: Thu, 4 Aug 2005 13:14:08 -0500 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp Message-ID: <200508041814.NAA02389@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Scalar: LoopStrengthReduce.cpp updated: 1.31 -> 1.32 --- Log message: Remove some more dead code. --- Diffs of the changes: (+0 -20) LoopStrengthReduce.cpp | 20 -------------------- 1 files changed, 20 deletions(-) Index: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp diff -u llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.31 llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.32 --- llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.31 Thu Aug 4 12:40:30 2005 +++ llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp Thu Aug 4 13:13:56 2005 @@ -37,21 +37,6 @@ namespace { Statistic<> NumReduced ("loop-reduce", "Number of GEPs strength reduced"); - class GEPCache { - public: - GEPCache() : CachedPHINode(0), Map() {} - - GEPCache *get(Value *v) { - std::map::iterator I = Map.find(v); - if (I == Map.end()) - I = Map.insert(std::pair(v, GEPCache())).first; - return &I->second; - } - - PHINode *CachedPHINode; - std::map Map; - }; - /// IVStrideUse - Keep track of one use of a strided induction variable, where /// the stride is stored externally. The Offset member keeps track of the /// offset from the IV, User is the actual user of the operand, and 'Operand' @@ -145,11 +130,6 @@ void StrengthReduceStridedIVUsers(Value *Stride, IVUsersOfOneStride &Uses, Loop *L, bool isOnlyStride); - - void strengthReduceGEP(GetElementPtrInst *GEPI, Loop *L, - GEPCache* GEPCache, - Instruction *InsertBefore, - std::set &DeadInsts); void DeleteTriviallyDeadInstructions(std::set &Insts); }; RegisterOpt X("loop-reduce", From lattner at cs.uiuc.edu Thu Aug 4 14:08:19 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu, 4 Aug 2005 14:08:19 -0500 Subject: [llvm-commits] CVS: llvm/test/Regression/Transforms/LoopStrengthReduce/ops_after_indvar.ll Message-ID: <200508041908.OAA02749@zion.cs.uiuc.edu> Changes in directory llvm/test/Regression/Transforms/LoopStrengthReduce: ops_after_indvar.ll updated: 1.2 -> 1.3 --- Log message: This testcase now passes --- Diffs of the changes: (+0 -1) ops_after_indvar.ll | 1 - 1 files changed, 1 deletion(-) Index: llvm/test/Regression/Transforms/LoopStrengthReduce/ops_after_indvar.ll diff -u llvm/test/Regression/Transforms/LoopStrengthReduce/ops_after_indvar.ll:1.2 llvm/test/Regression/Transforms/LoopStrengthReduce/ops_after_indvar.ll:1.3 --- llvm/test/Regression/Transforms/LoopStrengthReduce/ops_after_indvar.ll:1.2 Wed Aug 3 20:18:48 2005 +++ llvm/test/Regression/Transforms/LoopStrengthReduce/ops_after_indvar.ll Thu Aug 4 14:08:07 2005 @@ -2,7 +2,6 @@ ; gets reduced, making INDVAR dead. ; RUN: llvm-as < %s | opt -loop-reduce | llvm-dis | not grep INDVAR -; XFAIL: * declare bool %pred() declare int %getidx() From lattner at cs.uiuc.edu Thu Aug 4 14:08:27 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu, 4 Aug 2005 14:08:27 -0500 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp Message-ID: <200508041908.OAA02756@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Scalar: LoopStrengthReduce.cpp updated: 1.32 -> 1.33 --- Log message: Teach LSR about loop-variant expressions, such as loops like this: for (i = 0; i < N; ++i) A[i][foo()] = 0; here we still want to strength reduce the A[i] part, even though foo() is l-v. This also simplifies some of the 'CanReduce' logic. This implements Transforms/LoopStrengthReduce/ops_after_indvar.ll --- Diffs of the changes: (+93 -68) LoopStrengthReduce.cpp | 161 ++++++++++++++++++++++++++++--------------------- 1 files changed, 93 insertions(+), 68 deletions(-) Index: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp diff -u llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.32 llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.33 --- llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.32 Thu Aug 4 13:13:56 2005 +++ llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp Thu Aug 4 14:08:16 2005 @@ -166,8 +166,10 @@ // Do not insert casts into the middle of PHI node blocks. while (isa(InsertPt)) ++InsertPt; } - - return New = new CastInst(V, UIntPtrTy, V->getName(), InsertPt); + + New = new CastInst(V, UIntPtrTy, V->getName(), InsertPt); + DeadInsts.insert(cast(New)); + return New; } @@ -191,30 +193,6 @@ } -/// CanReduceSCEV - Return true if we can strength reduce this scalar evolution -/// in the specified loop. -static bool CanReduceSCEV(const SCEVHandle &SH, Loop *L) { - SCEVAddRecExpr *AddRec = dyn_cast(SH); - if (!AddRec || AddRec->getLoop() != L) return false; - - // FIXME: Generalize to non-affine IV's. - if (!AddRec->isAffine()) return false; - - // FIXME: generalize to IV's with more complex strides (must emit stride - // expression outside of loop!) - if (isa(AddRec->getOperand(1))) - return true; - - // We handle steps by unsigned values, because we know we won't have to insert - // a cast for them. - if (SCEVUnknown *SU = dyn_cast(AddRec->getOperand(1))) - if (SU->getValue()->getType()->isUnsigned()) - return true; - - // Otherwise, no, we can't handle it yet. - return false; -} - /// GetExpressionSCEV - Compute and return the SCEV for the specified /// instruction. SCEVHandle LoopStrengthReduce::GetExpressionSCEV(Instruction *Exp, Loop *L) { @@ -243,7 +221,9 @@ GEPVal = SCEVAddExpr::get(GEPVal, SCEVUnknown::getIntegerSCEV(Offset, UIntPtrTy)); } else { - SCEVHandle Idx = SE->getSCEV(getCastedVersionOf(GEP->getOperand(i))); + Value *OpVal = getCastedVersionOf(GEP->getOperand(i)); + SCEVHandle Idx = SE->getSCEV(OpVal); + uint64_t TypeSize = TD->getTypeSize(GTI.getIndexedType()); if (TypeSize != 1) Idx = SCEVMulExpr::get(Idx, @@ -253,10 +233,58 @@ } } - //assert(CanReduceSCEV(GEPVal, L) && "Cannot reduce this use of IV?"); return GEPVal; } +/// getSCEVStartAndStride - Compute the start and stride of this expression, +/// returning false if the expression is not a start/stride pair, or true if it +/// is. The stride must be a loop invariant expression, but the start may be +/// a mix of loop invariant and loop variant expressions. +static bool getSCEVStartAndStride(const SCEVHandle &SH, Loop *L, + SCEVHandle &Start, Value *&Stride) { + SCEVHandle TheAddRec = Start; // Initialize to zero. + + // If the outer level is an AddExpr, the operands are all start values except + // for a nested AddRecExpr. + if (SCEVAddExpr *AE = dyn_cast(SH)) { + for (unsigned i = 0, e = AE->getNumOperands(); i != e; ++i) + if (SCEVAddRecExpr *AddRec = + dyn_cast(AE->getOperand(i))) { + if (AddRec->getLoop() == L) + TheAddRec = SCEVAddExpr::get(AddRec, TheAddRec); + else + return false; // Nested IV of some sort? + } else { + Start = SCEVAddExpr::get(Start, AE->getOperand(i)); + } + + } else if (SCEVAddRecExpr *AddRec = dyn_cast(SH)) { + TheAddRec = SH; + } else { + return false; // not analyzable. + } + + SCEVAddRecExpr *AddRec = dyn_cast(TheAddRec); + if (!AddRec || AddRec->getLoop() != L) return false; + + // FIXME: Generalize to non-affine IV's. + if (!AddRec->isAffine()) return false; + + Start = SCEVAddExpr::get(Start, AddRec->getOperand(0)); + + // FIXME: generalize to IV's with more complex strides (must emit stride + // expression outside of loop!) + if (!isa(AddRec->getOperand(1))) + return false; + + SCEVConstant *StrideC = cast(AddRec->getOperand(1)); + Stride = StrideC->getValue(); + + assert(Stride->getType()->isUnsigned() && + "Constants should be canonicalized to unsigned!"); + return true; +} + /// AddUsersIfInteresting - Inspect the specified instruction. If it is a /// reducible SCEV, recursively add its users to the IVUsesByStride set and /// return true. Otherwise, return false. @@ -266,25 +294,16 @@ if (!Processed.insert(I).second) return true; // Instruction already handled. + // Get the symbolic expression for this instruction. SCEVHandle ISE = GetExpressionSCEV(I, L); - if (!CanReduceSCEV(ISE, L)) - return false; // Non-analyzable expression, e.g. a rem instr. + if (isa(ISE)) return false; + + // Get the start and stride for this expression. + SCEVHandle Start = SCEVUnknown::getIntegerSCEV(0, ISE->getType()); + Value *Stride = 0; + if (!getSCEVStartAndStride(ISE, L, Start, Stride)) + return false; // Non-reducible symbolic expression, bail out. - // NOT SAFE with generalized EXPRS - SCEVAddRecExpr *AR = cast(ISE); - SCEVHandle Start = AR->getStart(); - - // Get the step value, canonicalizing to an unsigned integer type so that - // lookups in the map will match. - Value *Step = 0; // Step of ISE. - if (SCEVConstant *SC = dyn_cast(AR->getOperand(1))) - /// Always get the step value as an unsigned value. - Step = ConstantExpr::getCast(SC->getValue(), - SC->getValue()->getType()->getUnsignedVersion()); - else - Step = cast(AR->getOperand(1))->getValue(); - assert(Step->getType()->isUnsigned() && "Bad step value!"); - for (Value::use_iterator UI = I->use_begin(), E = I->use_end(); UI != E;++UI){ Instruction *User = cast(*UI); @@ -294,20 +313,21 @@ // If this is an instruction defined in a nested loop, or outside this loop, // don't recurse into it. + bool AddUserToIVUsers = false; if (LI->getLoopFor(User->getParent()) != L) { DEBUG(std::cerr << "FOUND USER in nested loop: " << *User << " OF SCEV: " << *ISE << "\n"); - - // Okay, we found a user that we cannot reduce. Analyze the instruction - // and decide what to do with it. - IVUsesByStride[Step].addUser(Start, User, I); + AddUserToIVUsers = true; } else if (!AddUsersIfInteresting(User, L, Processed)) { DEBUG(std::cerr << "FOUND USER: " << *User << " OF SCEV: " << *ISE << "\n"); + AddUserToIVUsers = true; + } + if (AddUserToIVUsers) { // Okay, we found a user that we cannot reduce. Analyze the instruction // and decide what to do with it. - IVUsesByStride[Step].addUser(Start, User, I); + IVUsesByStride[Stride].addUser(Start, User, I); } } return true; @@ -372,28 +392,27 @@ /// GetImmediateValues - Look at Val, and pull out any additions of constants /// that can fit into the immediate field of instructions in the target. -static SCEVHandle GetImmediateValues(SCEVHandle Val, bool isAddress) { - if (!isAddress) - return SCEVUnknown::getIntegerSCEV(0, Val->getType()); - if (isTargetConstant(Val)) +static SCEVHandle GetImmediateValues(SCEVHandle Val, bool isAddress, Loop *L) { + if (isAddress && isTargetConstant(Val)) return Val; if (SCEVAddExpr *SAE = dyn_cast(Val)) { unsigned i = 0; - for (; i != SAE->getNumOperands(); ++i) - if (isTargetConstant(SAE->getOperand(i))) { - SCEVHandle ImmVal = SAE->getOperand(i); + SCEVHandle Imm = SCEVUnknown::getIntegerSCEV(0, Val->getType()); - // If there are any other immediates that we can handle here, pull them - // out too. - for (++i; i != SAE->getNumOperands(); ++i) - if (isTargetConstant(SAE->getOperand(i))) - ImmVal = SCEVAddExpr::get(ImmVal, SAE->getOperand(i)); - return ImmVal; + for (; i != SAE->getNumOperands(); ++i) + if (isAddress && isTargetConstant(SAE->getOperand(i))) { + Imm = SCEVAddExpr::get(Imm, SAE->getOperand(i)); + } else if (!SAE->getOperand(i)->isLoopInvariant(L)) { + // If this is a loop-variant expression, it must stay in the immediate + // field of the expression. + Imm = SCEVAddExpr::get(Imm, SAE->getOperand(i)); } + + return Imm; } else if (SCEVAddRecExpr *SARE = dyn_cast(Val)) { // Try to pull immediates out of the start value of nested addrec's. - return GetImmediateValues(SARE->getStart(), isAddress); + return GetImmediateValues(SARE->getStart(), isAddress, L); } return SCEVUnknown::getIntegerSCEV(0, Val->getType()); @@ -427,10 +446,16 @@ // instructions. If we can represent anything there, move it to the imm // fields of the BasedUsers. for (unsigned i = 0, e = UsersToProcess.size(); i != e; ++i) { - bool isAddress = isa(UsersToProcess[i].second.Inst) || - isa(UsersToProcess[i].second.Inst); - UsersToProcess[i].second.Imm = GetImmediateValues(UsersToProcess[i].first, - isAddress); + // Addressing modes can be folded into loads and stores. Be careful that + // the store is through the expression, not of the expression though. + bool isAddress = isa(UsersToProcess[i].second.Inst); + if (StoreInst *SI = dyn_cast(UsersToProcess[i].second.Inst)) + if (SI->getOperand(1) == UsersToProcess[i].second.OperandValToReplace) + isAddress = true; + + UsersToProcess[i].second.Imm = + GetImmediateValues(UsersToProcess[i].first, isAddress, L); + UsersToProcess[i].first = SCEV::getMinusSCEV(UsersToProcess[i].first, UsersToProcess[i].second.Imm); From lattner at cs.uiuc.edu Thu Aug 4 14:26:30 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu, 4 Aug 2005 14:26:30 -0500 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp Message-ID: <200508041926.OAA04535@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Scalar: LoopStrengthReduce.cpp updated: 1.33 -> 1.34 --- Log message: Fix a case that caused this to crash on 178.galgel --- Diffs of the changes: (+6 -0) LoopStrengthReduce.cpp | 6 ++++++ 1 files changed, 6 insertions(+) Index: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp diff -u llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.33 llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.34 --- llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.33 Thu Aug 4 14:08:16 2005 +++ llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp Thu Aug 4 14:26:19 2005 @@ -415,6 +415,12 @@ return GetImmediateValues(SARE->getStart(), isAddress, L); } + if (!Val->isLoopInvariant(L)) { + // If this is a loop-variant expression, it must stay in the immediate + // field of the expression. + return Val; + } + return SCEVUnknown::getIntegerSCEV(0, Val->getType()); } From lattner at cs.uiuc.edu Thu Aug 4 14:39:12 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu, 4 Aug 2005 14:39:12 -0500 Subject: [llvm-commits] CVS: llvm-test/MultiSource/Applications/Makefile Message-ID: <200508041939.OAA06958@zion.cs.uiuc.edu> Changes in directory llvm-test/MultiSource/Applications: Makefile updated: 1.19 -> 1.20 --- Log message: hexxagon works fine on Darwin with the last round of CFE changes --- Diffs of the changes: (+0 -5) Makefile | 5 ----- 1 files changed, 5 deletions(-) Index: llvm-test/MultiSource/Applications/Makefile diff -u llvm-test/MultiSource/Applications/Makefile:1.19 llvm-test/MultiSource/Applications/Makefile:1.20 --- llvm-test/MultiSource/Applications/Makefile:1.19 Fri May 20 10:50:13 2005 +++ llvm-test/MultiSource/Applications/Makefile Thu Aug 4 14:39:01 2005 @@ -6,11 +6,6 @@ PARALLEL_DIRS = Burg aha sgefa siod lambda-0.1.3 d spiff hbd treecc SPASS -# All platforms except Darwin should be able to handle hexxagon -ifneq ($(OS),Darwin) -PARALLEL_DIRS += hexxagon -endif - # Obsequi uses Linux-only features; need to fix that ifeq ($(OS),Linux) PARALLEL_DIRS += obsequi From lattner at cs.uiuc.edu Thu Aug 4 14:55:51 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu, 4 Aug 2005 14:55:51 -0500 Subject: [llvm-commits] CVS: llvm/test/Regression/CodeGen/X86/2002-12-23-LocalRAProblem.llx 2002-12-23-SubProblem.llx 2003-08-03-CallArgLiveRanges.llx 2004-02-08-UnwindSupport.llx Message-ID: <200508041955.OAA07102@zion.cs.uiuc.edu> Changes in directory llvm/test/Regression/CodeGen/X86: 2002-12-23-LocalRAProblem.llx updated: 1.4 -> 1.5 2002-12-23-SubProblem.llx updated: 1.4 -> 1.5 2003-08-03-CallArgLiveRanges.llx updated: 1.2 -> 1.3 2004-02-08-UnwindSupport.llx updated: 1.1 -> 1.2 --- Log message: None of these tests should require a working lli, they are codegen tests, not execution tests. --- Diffs of the changes: (+4 -5) 2002-12-23-LocalRAProblem.llx | 3 +-- 2002-12-23-SubProblem.llx | 2 +- 2003-08-03-CallArgLiveRanges.llx | 2 +- 2004-02-08-UnwindSupport.llx | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) Index: llvm/test/Regression/CodeGen/X86/2002-12-23-LocalRAProblem.llx diff -u llvm/test/Regression/CodeGen/X86/2002-12-23-LocalRAProblem.llx:1.4 llvm/test/Regression/CodeGen/X86/2002-12-23-LocalRAProblem.llx:1.5 --- llvm/test/Regression/CodeGen/X86/2002-12-23-LocalRAProblem.llx:1.4 Thu Oct 2 01:13:19 2003 +++ llvm/test/Regression/CodeGen/X86/2002-12-23-LocalRAProblem.llx Thu Aug 4 14:55:39 2005 @@ -1,5 +1,4 @@ -; RUN: llvm-as < %s | lli -force-interpreter=false -regalloc=simple -;-print-machineinstrs +; RUN: llvm-as < %s | llc -march=x86 -regalloc=simple int %main() { %A = add int 0, 0 ; %A = 0 Index: llvm/test/Regression/CodeGen/X86/2002-12-23-SubProblem.llx diff -u llvm/test/Regression/CodeGen/X86/2002-12-23-SubProblem.llx:1.4 llvm/test/Regression/CodeGen/X86/2002-12-23-SubProblem.llx:1.5 --- llvm/test/Regression/CodeGen/X86/2002-12-23-SubProblem.llx:1.4 Thu Oct 2 01:13:19 2003 +++ llvm/test/Regression/CodeGen/X86/2002-12-23-SubProblem.llx Thu Aug 4 14:55:39 2005 @@ -1,4 +1,4 @@ -; RUN: llvm-as < %s | lli -force-interpreter=false -regalloc=simple +; RUN: llvm-as < %s | llc -march=x86 -regalloc=simple int %main(int %B) { ;%B = add int 0, 1 Index: llvm/test/Regression/CodeGen/X86/2003-08-03-CallArgLiveRanges.llx diff -u llvm/test/Regression/CodeGen/X86/2003-08-03-CallArgLiveRanges.llx:1.2 llvm/test/Regression/CodeGen/X86/2003-08-03-CallArgLiveRanges.llx:1.3 --- llvm/test/Regression/CodeGen/X86/2003-08-03-CallArgLiveRanges.llx:1.2 Mon Sep 15 15:02:53 2003 +++ llvm/test/Regression/CodeGen/X86/2003-08-03-CallArgLiveRanges.llx Thu Aug 4 14:55:39 2005 @@ -3,7 +3,7 @@ ; it makes a ton of annoying overlapping live ranges. This code should not ; cause spills! ; -; RUN: llvm-as < %s | lli -stats 2>&1 | not grep spilled +; RUN: llvm-as < %s | llc -march=x86 -stats 2>&1 | not grep spilled target endian = little target pointersize = 32 Index: llvm/test/Regression/CodeGen/X86/2004-02-08-UnwindSupport.llx diff -u llvm/test/Regression/CodeGen/X86/2004-02-08-UnwindSupport.llx:1.1 llvm/test/Regression/CodeGen/X86/2004-02-08-UnwindSupport.llx:1.2 --- llvm/test/Regression/CodeGen/X86/2004-02-08-UnwindSupport.llx:1.1 Sun Feb 8 13:40:58 2004 +++ llvm/test/Regression/CodeGen/X86/2004-02-08-UnwindSupport.llx Thu Aug 4 14:55:39 2005 @@ -1,4 +1,4 @@ -; RUN: llvm-as < %s | lli -enable-correct-eh-support +; RUN: llvm-as < %s | llc -enable-correct-eh-support int %test() { unwind From lattner at cs.uiuc.edu Thu Aug 4 14:56:46 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu, 4 Aug 2005 14:56:46 -0500 Subject: [llvm-commits] CVS: llvm/test/Regression/Transforms/LoopSimplify/2003-12-10-ExitBlocksProblem.ll Message-ID: <200508041956.OAA07137@zion.cs.uiuc.edu> Changes in directory llvm/test/Regression/Transforms/LoopSimplify: 2003-12-10-ExitBlocksProblem.ll updated: 1.1 -> 1.2 --- Log message: This should not run lli, that is for llvm-test. --- Diffs of the changes: (+1 -1) 2003-12-10-ExitBlocksProblem.ll | 2 +- 1 files changed, 1 insertion(+), 1 deletion(-) Index: llvm/test/Regression/Transforms/LoopSimplify/2003-12-10-ExitBlocksProblem.ll diff -u llvm/test/Regression/Transforms/LoopSimplify/2003-12-10-ExitBlocksProblem.ll:1.1 llvm/test/Regression/Transforms/LoopSimplify/2003-12-10-ExitBlocksProblem.ll:1.2 --- llvm/test/Regression/Transforms/LoopSimplify/2003-12-10-ExitBlocksProblem.ll:1.1 Wed Dec 10 11:09:35 2003 +++ llvm/test/Regression/Transforms/LoopSimplify/2003-12-10-ExitBlocksProblem.ll Thu Aug 4 14:56:35 2005 @@ -4,7 +4,7 @@ ; ; This is distilled from a monsterous crafty example. -; RUN: llvm-as < %s | opt -licm | lli +; RUN: llvm-as < %s | opt -licm -disable-output %G = weak global int 0 ; [#uses=13] From lattner at cs.uiuc.edu Thu Aug 4 15:03:44 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu, 4 Aug 2005 15:03:44 -0500 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp Message-ID: <200508042003.PAA07256@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Scalar: LoopStrengthReduce.cpp updated: 1.34 -> 1.35 --- Log message: * Refactor some code into a new BasedUser::RewriteInstructionToUseNewBase method. * Fix a crash on 178.galgel, where we would insert expressions before PHI nodes instead of into the PHI node predecessor blocks. --- Diffs of the changes: (+48 -16) LoopStrengthReduce.cpp | 64 ++++++++++++++++++++++++++++++++++++------------- 1 files changed, 48 insertions(+), 16 deletions(-) Index: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp diff -u llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.34 llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.35 --- llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.34 Thu Aug 4 14:26:19 2005 +++ llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp Thu Aug 4 15:03:32 2005 @@ -356,6 +356,10 @@ BasedUser(Instruction *I, Value *Op, const SCEVHandle &IMM) : Inst(I), OperandValToReplace(Op), Imm(IMM), EmittedBase(0) {} + // Once we rewrite the code to insert the new IVs we want, update the + // operands of Inst to use the new expression 'NewBase', with 'Imm' added + // to it. + void RewriteInstructionToUseNewBase(Value *NewBase, SCEVExpander &Rewriter); // No need to compare these. bool operator<(const BasedUser &BU) const { return 0; } @@ -372,6 +376,45 @@ std::cerr << " Inst: " << *Inst; } +// Once we rewrite the code to insert the new IVs we want, update the +// operands of Inst to use the new expression 'NewBase', with 'Imm' added +// to it. +void BasedUser::RewriteInstructionToUseNewBase(Value *NewBase, + SCEVExpander &Rewriter) { + if (!isa(Inst)) { + SCEVHandle NewValSCEV = SCEVAddExpr::get(SCEVUnknown::get(NewBase), Imm); + Value *NewVal = Rewriter.expandCodeFor(NewValSCEV, Inst, + OperandValToReplace->getType()); + + // Replace the use of the operand Value with the new Phi we just created. + Inst->replaceUsesOfWith(OperandValToReplace, NewVal); + DEBUG(std::cerr << " CHANGED: IMM =" << *Imm << " Inst = " << *Inst); + return; + } + + // PHI nodes are more complex. We have to insert one copy of the NewBase+Imm + // expression into each operand block that uses it. + PHINode *PN = cast(Inst); + for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) { + if (PN->getIncomingValue(i) == OperandValToReplace) { + // FIXME: this should split any critical edges. + + // Insert the code into the end of the predecessor block. + BasicBlock::iterator InsertPt = PN->getIncomingBlock(i)->getTerminator(); + + SCEVHandle NewValSCEV = SCEVAddExpr::get(SCEVUnknown::get(NewBase), Imm); + Value *NewVal = Rewriter.expandCodeFor(NewValSCEV, InsertPt, + OperandValToReplace->getType()); + + // Replace the use of the operand Value with the new Phi we just created. + PN->setIncomingValue(i, NewVal); + Rewriter.clear(); + } + } + DEBUG(std::cerr << " CHANGED: IMM =" << *Imm << " Inst = " << *Inst); +} + + /// isTargetConstant - Return true if the following can be referenced by the /// immediate field of a target instruction. static bool isTargetConstant(const SCEVHandle &V) { @@ -526,20 +569,14 @@ // Clear the SCEVExpander's expression map so that we are guaranteed // to have the code emitted where we expect it. Rewriter.clear(); - SCEVHandle NewValSCEV = SCEVAddExpr::get(SCEVUnknown::get(NewPHI), - User.Imm); - Value *Replaced = User.OperandValToReplace; - Value *newVal = Rewriter.expandCodeFor(NewValSCEV, User.Inst, - Replaced->getType()); - - // Replace the use of the operand Value with the new Phi we just created. - User.Inst->replaceUsesOfWith(Replaced, newVal); - DEBUG(std::cerr << " CHANGED: IMM =" << *User.Imm << " Inst = " - << *User.Inst); + + // Now that we know what we need to do, insert code before User for the + // immediate and any loop-variant expressions. + User.RewriteInstructionToUseNewBase(NewPHI, Rewriter); // Mark old value we replaced as possibly dead, so that it is elminated // if we just replaced the last use of that value. - DeadInsts.insert(cast(Replaced)); + DeadInsts.insert(cast(User.OperandValToReplace)); UsersToProcess.erase(UsersToProcess.begin()); ++NumReduced; @@ -549,11 +586,6 @@ // IMPORTANT TODO: Figure out how to partition the IV's with this stride, but // different starting values, into different PHIs. - - // BEFORE writing this, it's probably useful to handle GEP's. - - // NOTE: pull all constants together, for REG+IMM addressing, include &GV in - // 'IMM' if the target supports it. } From natebegeman at mac.com Thu Aug 4 15:05:41 2005 From: natebegeman at mac.com (Nate Begeman) Date: Thu, 4 Aug 2005 15:05:41 -0500 Subject: [llvm-commits] CVS: llvm-test/MultiSource/Applications/hexxagon/bitboard64.h Message-ID: <200508042005.PAA07284@zion.cs.uiuc.edu> Changes in directory llvm-test/MultiSource/Applications/hexxagon: bitboard64.h updated: 1.1 -> 1.2 --- Log message: Include missing header, allowing this to build with gcc 4 --- Diffs of the changes: (+1 -0) bitboard64.h | 1 + 1 files changed, 1 insertion(+) Index: llvm-test/MultiSource/Applications/hexxagon/bitboard64.h diff -u llvm-test/MultiSource/Applications/hexxagon/bitboard64.h:1.1 llvm-test/MultiSource/Applications/hexxagon/bitboard64.h:1.2 --- llvm-test/MultiSource/Applications/hexxagon/bitboard64.h:1.1 Fri Sep 10 09:25:52 2004 +++ llvm-test/MultiSource/Applications/hexxagon/bitboard64.h Thu Aug 4 15:05:30 2005 @@ -25,6 +25,7 @@ #include #include +#include class BitBoard64 { From natebegeman at mac.com Thu Aug 4 15:49:59 2005 From: natebegeman at mac.com (Nate Begeman) Date: Thu, 4 Aug 2005 15:49:59 -0500 Subject: [llvm-commits] CVS: llvm/lib/Target/PowerPC/PPC32RegisterInfo.cpp PPC32RegisterInfo.td PPC64RegisterInfo.cpp PPC64RegisterInfo.td PowerPC.h PowerPCTargetMachine.cpp Message-ID: <200508042049.PAA07824@zion.cs.uiuc.edu> Changes in directory llvm/lib/Target/PowerPC: PPC32RegisterInfo.cpp updated: 1.15 -> 1.16 PPC32RegisterInfo.td updated: 1.4 -> 1.5 PPC64RegisterInfo.cpp updated: 1.9 -> 1.10 PPC64RegisterInfo.td updated: 1.3 -> 1.4 PowerPC.h updated: 1.17 -> 1.18 PowerPCTargetMachine.cpp updated: 1.58 -> 1.59 --- Log message: Use the new subtarget support to automatically choose the correct ABI and asm printer for PowerPC if one is not specified. --- Diffs of the changes: (+35 -18) PPC32RegisterInfo.cpp | 5 ----- PPC32RegisterInfo.td | 2 +- PPC64RegisterInfo.cpp | 5 ----- PPC64RegisterInfo.td | 2 +- PowerPC.h | 5 +++++ PowerPCTargetMachine.cpp | 34 ++++++++++++++++++++++++++++------ 6 files changed, 35 insertions(+), 18 deletions(-) Index: llvm/lib/Target/PowerPC/PPC32RegisterInfo.cpp diff -u llvm/lib/Target/PowerPC/PPC32RegisterInfo.cpp:1.15 llvm/lib/Target/PowerPC/PPC32RegisterInfo.cpp:1.16 --- llvm/lib/Target/PowerPC/PPC32RegisterInfo.cpp:1.15 Sat Jul 30 13:33:25 2005 +++ llvm/lib/Target/PowerPC/PPC32RegisterInfo.cpp Thu Aug 4 15:49:48 2005 @@ -31,11 +31,6 @@ #include using namespace llvm; -namespace llvm { - // Switch toggling compilation for AIX - extern cl::opt AIX; -} - PPC32RegisterInfo::PPC32RegisterInfo() : PPC32GenRegisterInfo(PPC::ADJCALLSTACKDOWN, PPC::ADJCALLSTACKUP) { ImmToIdxMap[PPC::LD] = PPC::LDX; ImmToIdxMap[PPC::STD] = PPC::STDX; Index: llvm/lib/Target/PowerPC/PPC32RegisterInfo.td diff -u llvm/lib/Target/PowerPC/PPC32RegisterInfo.td:1.4 llvm/lib/Target/PowerPC/PPC32RegisterInfo.td:1.5 --- llvm/lib/Target/PowerPC/PPC32RegisterInfo.td:1.4 Tue Apr 12 02:04:16 2005 +++ llvm/lib/Target/PowerPC/PPC32RegisterInfo.td Thu Aug 4 15:49:48 2005 @@ -22,7 +22,7 @@ { let Methods = [{ iterator allocation_order_begin(MachineFunction &MF) const { - return begin() + (AIX ? 1 : 0); + return begin() + ((TargetAIX == PPCTarget) ? 1 : 0); } iterator allocation_order_end(MachineFunction &MF) const { if (hasFP(MF)) Index: llvm/lib/Target/PowerPC/PPC64RegisterInfo.cpp diff -u llvm/lib/Target/PowerPC/PPC64RegisterInfo.cpp:1.9 llvm/lib/Target/PowerPC/PPC64RegisterInfo.cpp:1.10 --- llvm/lib/Target/PowerPC/PPC64RegisterInfo.cpp:1.9 Fri Apr 22 12:54:30 2005 +++ llvm/lib/Target/PowerPC/PPC64RegisterInfo.cpp Thu Aug 4 15:49:48 2005 @@ -31,11 +31,6 @@ #include using namespace llvm; -namespace llvm { - // Switch toggling compilation for AIX - extern cl::opt AIX; -} - PPC64RegisterInfo::PPC64RegisterInfo() : PPC64GenRegisterInfo(PPC::ADJCALLSTACKDOWN, PPC::ADJCALLSTACKUP) { ImmToIdxMap[PPC::LD] = PPC::LDX; ImmToIdxMap[PPC::STD] = PPC::STDX; Index: llvm/lib/Target/PowerPC/PPC64RegisterInfo.td diff -u llvm/lib/Target/PowerPC/PPC64RegisterInfo.td:1.3 llvm/lib/Target/PowerPC/PPC64RegisterInfo.td:1.4 --- llvm/lib/Target/PowerPC/PPC64RegisterInfo.td:1.3 Sat Aug 21 15:14:40 2004 +++ llvm/lib/Target/PowerPC/PPC64RegisterInfo.td Thu Aug 4 15:49:48 2005 @@ -22,7 +22,7 @@ { let Methods = [{ iterator allocation_order_begin(MachineFunction &MF) const { - return begin() + (AIX ? 1 : 0); + return begin() + ((TargetAIX == PPCTarget) ? 1 : 0); } iterator allocation_order_end(MachineFunction &MF) const { if (hasFP(MF)) Index: llvm/lib/Target/PowerPC/PowerPC.h diff -u llvm/lib/Target/PowerPC/PowerPC.h:1.17 llvm/lib/Target/PowerPC/PowerPC.h:1.18 --- llvm/lib/Target/PowerPC/PowerPC.h:1.17 Thu Jul 21 15:44:42 2005 +++ llvm/lib/Target/PowerPC/PowerPC.h Thu Aug 4 15:49:48 2005 @@ -22,6 +22,10 @@ class FunctionPass; class TargetMachine; +enum PPCTargetEnum { + TargetDefault, TargetAIX, TargetDarwin +}; + FunctionPass *createPPCBranchSelectionPass(); FunctionPass *createPPC32ISelSimple(TargetMachine &TM); FunctionPass *createPPC32ISelPattern(TargetMachine &TM); @@ -31,6 +35,7 @@ extern bool GPOPT; extern bool PICEnabled; +extern PPCTargetEnum PPCTarget; } // end namespace llvm; // GCC #defines PPC on Linux but we use it as our namespace name Index: llvm/lib/Target/PowerPC/PowerPCTargetMachine.cpp diff -u llvm/lib/Target/PowerPC/PowerPCTargetMachine.cpp:1.58 llvm/lib/Target/PowerPC/PowerPCTargetMachine.cpp:1.59 --- llvm/lib/Target/PowerPC/PowerPCTargetMachine.cpp:1.58 Thu Aug 4 02:12:08 2005 +++ llvm/lib/Target/PowerPC/PowerPCTargetMachine.cpp Thu Aug 4 15:49:48 2005 @@ -19,6 +19,7 @@ #include "PPC64JITInfo.h" #include "llvm/Module.h" #include "llvm/PassManager.h" +#include "llvm/Analysis/Verifier.h" #include "llvm/CodeGen/IntrinsicLowering.h" #include "llvm/CodeGen/MachineFunction.h" #include "llvm/CodeGen/Passes.h" @@ -30,11 +31,17 @@ using namespace llvm; bool llvm::GPOPT = false; +PPCTargetEnum llvm::PPCTarget = TargetDefault; namespace llvm { - cl::opt AIX("aix", - cl::desc("Generate AIX/xcoff instead of Darwin/MachO"), - cl::Hidden); + cl::opt + PPCTargetArg( + cl::desc("Force generation of code for a specific PPC target:"), + cl::values( + clEnumValN(TargetAIX, "aix", " Enable AIX codegen"), + clEnumValN(TargetDarwin,"darwin"," Enable Darwin codegen"), + clEnumValEnd), + cl::location(PPCTarget), cl::init(TargetDefault)); cl::opt EnablePPCLSR("enable-lsr-for-ppc", cl::desc("Enable LSR for PPC (beta)"), cl::Hidden); @@ -62,7 +69,12 @@ const Module &M, const TargetData &TD, const PowerPCFrameInfo &TFI) -: TargetMachine(name, IL, TD), FrameInfo(TFI), Subtarget(M) {} +: TargetMachine(name, IL, TD), FrameInfo(TFI), Subtarget(M) { + if (TargetDefault == PPCTarget) { + if (Subtarget.IsAIX()) PPCTarget = TargetAIX; + if (Subtarget.IsDarwin()) PPCTarget = TargetDarwin; + } +} unsigned PPC32TargetMachine::getJITMatchQuality() { #if defined(__POWERPC__) || defined (__ppc__) || defined(_POWER) @@ -84,6 +96,7 @@ if (EnablePPCLSR) { PM.add(createLoopStrengthReducePass()); + PM.add(createVerifierPass()); PM.add(createCFGSimplificationPass()); } @@ -122,10 +135,19 @@ // Must run branch selection immediately preceding the asm printer PM.add(createPPCBranchSelectionPass()); - if (AIX) + // Decide which asm printer to use. If the user has not specified one on + // the command line, choose whichever one matches the default (current host). + switch (PPCTarget) { + case TargetDefault: + assert(0 && "Default host has no asm printer!"); + break; + case TargetAIX: PM.add(createAIXAsmPrinter(Out, *this)); - else + break; + case TargetDarwin: PM.add(createDarwinAsmPrinter(Out, *this)); + break; + } PM.add(createMachineCodeDeleter()); return false; From natebegeman at mac.com Thu Aug 4 16:04:20 2005 From: natebegeman at mac.com (Nate Begeman) Date: Thu, 4 Aug 2005 16:04:20 -0500 Subject: [llvm-commits] CVS: llvm/lib/Target/PowerPC/PowerPCAsmPrinter.cpp Message-ID: <200508042104.QAA08857@zion.cs.uiuc.edu> Changes in directory llvm/lib/Target/PowerPC: PowerPCAsmPrinter.cpp updated: 1.84 -> 1.85 --- Log message: Hack to naturally align doubles in the constant pool. Remove this once we know what The Right Thing To Do is. --- Diffs of the changes: (+6 -1) PowerPCAsmPrinter.cpp | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletion(-) Index: llvm/lib/Target/PowerPC/PowerPCAsmPrinter.cpp diff -u llvm/lib/Target/PowerPC/PowerPCAsmPrinter.cpp:1.84 llvm/lib/Target/PowerPC/PowerPCAsmPrinter.cpp:1.85 --- llvm/lib/Target/PowerPC/PowerPCAsmPrinter.cpp:1.84 Tue Aug 2 14:25:03 2005 +++ llvm/lib/Target/PowerPC/PowerPCAsmPrinter.cpp Thu Aug 4 16:04:09 2005 @@ -427,7 +427,12 @@ for (unsigned i = 0, e = CP.size(); i != e; ++i) { O << "\t.const\n"; - emitAlignment(TD.getTypeAlignmentShift(CP[i]->getType())); + // FIXME: force doubles to be naturally aligned. We should handle this + // more correctly in the future. + if (Type::DoubleTy == CP[i]->getType()) + emitAlignment(3); + else + emitAlignment(TD.getTypeAlignmentShift(CP[i]->getType())); O << ".CPI" << CurrentFnName << "_" << i << ":\t\t\t\t\t" << CommentString << *CP[i] << "\n"; emitGlobalConstant(CP[i]); From natebegeman at mac.com Thu Aug 4 16:43:39 2005 From: natebegeman at mac.com (Nate Begeman) Date: Thu, 4 Aug 2005 16:43:39 -0500 Subject: [llvm-commits] CVS: llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp Message-ID: <200508042143.QAA08972@zion.cs.uiuc.edu> Changes in directory llvm/lib/CodeGen/SelectionDAG: LegalizeDAG.cpp updated: 1.152 -> 1.153 --- Log message: Fix a fixme in LegalizeDAG --- Diffs of the changes: (+2 -7) LegalizeDAG.cpp | 9 ++------- 1 files changed, 2 insertions(+), 7 deletions(-) Index: llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp diff -u llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:1.152 llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:1.153 --- llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:1.152 Wed Aug 3 15:31:37 2005 +++ llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp Thu Aug 4 16:43:28 2005 @@ -1486,13 +1486,8 @@ case ISD::FCOS: FnName = VT == MVT::f32 ? "cosf" : "cos"; break; default: assert(0 && "Unreachable!"); } - std::vector > Args; - Args.push_back(std::make_pair(Tmp1, T)); - // FIXME: should use ExpandLibCall! - std::pair CallResult = - TLI.LowerCallTo(DAG.getEntryNode(), T, false, CallingConv::C, true, - DAG.getExternalSymbol(FnName, VT), Args, DAG); - Result = LegalizeOp(CallResult.first); + SDOperand Dummy; + Result = ExpandLibCall(FnName, Node, Dummy); break; } default: From lattner at cs.uiuc.edu Thu Aug 4 17:34:16 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu, 4 Aug 2005 17:34:16 -0500 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp Message-ID: <200508042234.RAA09230@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Scalar: LoopStrengthReduce.cpp updated: 1.35 -> 1.36 --- Log message: Modify how immediates are removed from base expressions to deal with the fact that the symbolic evaluator is not always able to use subtraction to remove expressions. This makes the code faster, and fixes the last crash on 178.galgel. Finally, add a statistic to see how many phi nodes are inserted. On 178.galgel, we get the follow stats: 2562 loop-reduce - Number of PHIs inserted 3927 loop-reduce - Number of GEPs strength reduced --- Diffs of the changes: (+40 -25) LoopStrengthReduce.cpp | 65 ++++++++++++++++++++++++++++++------------------- 1 files changed, 40 insertions(+), 25 deletions(-) Index: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp diff -u llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.35 llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.36 --- llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.35 Thu Aug 4 15:03:32 2005 +++ llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp Thu Aug 4 17:34:05 2005 @@ -36,6 +36,7 @@ namespace { Statistic<> NumReduced ("loop-reduce", "Number of GEPs strength reduced"); + Statistic<> NumInserted("loop-reduce", "Number of PHIs inserted"); /// IVStrideUse - Keep track of one use of a strided induction variable, where /// the stride is stored externally. The Offset member keeps track of the @@ -433,38 +434,54 @@ return false; } -/// GetImmediateValues - Look at Val, and pull out any additions of constants +/// MoveImmediateValues - Look at Val, and pull out any additions of constants /// that can fit into the immediate field of instructions in the target. -static SCEVHandle GetImmediateValues(SCEVHandle Val, bool isAddress, Loop *L) { - if (isAddress && isTargetConstant(Val)) - return Val; - +/// Accumulate these immediate values into the Imm value. +static void MoveImmediateValues(SCEVHandle &Val, SCEVHandle &Imm, + bool isAddress, Loop *L) { if (SCEVAddExpr *SAE = dyn_cast(Val)) { - unsigned i = 0; - SCEVHandle Imm = SCEVUnknown::getIntegerSCEV(0, Val->getType()); - - for (; i != SAE->getNumOperands(); ++i) + std::vector NewOps; + NewOps.reserve(SAE->getNumOperands()); + + for (unsigned i = 0; i != SAE->getNumOperands(); ++i) if (isAddress && isTargetConstant(SAE->getOperand(i))) { Imm = SCEVAddExpr::get(Imm, SAE->getOperand(i)); } else if (!SAE->getOperand(i)->isLoopInvariant(L)) { // If this is a loop-variant expression, it must stay in the immediate // field of the expression. Imm = SCEVAddExpr::get(Imm, SAE->getOperand(i)); + } else { + NewOps.push_back(SAE->getOperand(i)); } - - return Imm; + + if (NewOps.empty()) + Val = SCEVUnknown::getIntegerSCEV(0, Val->getType()); + else + Val = SCEVAddExpr::get(NewOps); + return; } else if (SCEVAddRecExpr *SARE = dyn_cast(Val)) { // Try to pull immediates out of the start value of nested addrec's. - return GetImmediateValues(SARE->getStart(), isAddress, L); + SCEVHandle Start = SARE->getStart(); + MoveImmediateValues(Start, Imm, isAddress, L); + + if (Start != SARE->getStart()) { + std::vector Ops(SARE->op_begin(), SARE->op_end()); + Ops[0] = Start; + Val = SCEVAddRecExpr::get(Ops, SARE->getLoop()); + } + return; } - if (!Val->isLoopInvariant(L)) { - // If this is a loop-variant expression, it must stay in the immediate - // field of the expression. - return Val; + // Loop-variant expressions must stay in the immediate field of the + // expression. + if ((isAddress && isTargetConstant(Val)) || + !Val->isLoopInvariant(L)) { + Imm = SCEVAddExpr::get(Imm, Val); + Val = SCEVUnknown::getIntegerSCEV(0, Val->getType()); + return; } - - return SCEVUnknown::getIntegerSCEV(0, Val->getType()); + + // Otherwise, no immediates to move. } /// StrengthReduceStridedIVUsers - Strength reduce all of the users of a single @@ -502,14 +519,11 @@ if (SI->getOperand(1) == UsersToProcess[i].second.OperandValToReplace) isAddress = true; - UsersToProcess[i].second.Imm = - GetImmediateValues(UsersToProcess[i].first, isAddress, L); - - UsersToProcess[i].first = SCEV::getMinusSCEV(UsersToProcess[i].first, - UsersToProcess[i].second.Imm); + MoveImmediateValues(UsersToProcess[i].first, UsersToProcess[i].second.Imm, + isAddress, L); - DEBUG(std::cerr << "BASE: " << *UsersToProcess[i].first); - DEBUG(UsersToProcess[i].second.dump()); + assert(UsersToProcess[i].first->isLoopInvariant(L) && + "Base value is not loop invariant!"); } SCEVExpander Rewriter(*SE, *LI); @@ -545,6 +559,7 @@ // Create a new Phi for this base, and stick it in the loop header. const Type *ReplacedTy = Base->getType(); PHINode *NewPHI = new PHINode(ReplacedTy, "iv.", PhiInsertBefore); + ++NumInserted; // Emit the initial base value into the loop preheader, and add it to the // Phi node. From lattner at cs.uiuc.edu Thu Aug 4 17:49:43 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu, 4 Aug 2005 17:49:43 -0500 Subject: [llvm-commits] CVS: llvm/test/Regression/Transforms/CondProp/phisimplify.ll Message-ID: <200508042249.RAA09380@zion.cs.uiuc.edu> Changes in directory llvm/test/Regression/Transforms/CondProp: phisimplify.ll added (r1.1) --- Log message: add a testcase nate requested --- Diffs of the changes: (+33 -0) phisimplify.ll | 33 +++++++++++++++++++++++++++++++++ 1 files changed, 33 insertions(+) Index: llvm/test/Regression/Transforms/CondProp/phisimplify.ll diff -c /dev/null llvm/test/Regression/Transforms/CondProp/phisimplify.ll:1.1 *** /dev/null Thu Aug 4 17:49:42 2005 --- llvm/test/Regression/Transforms/CondProp/phisimplify.ll Thu Aug 4 17:49:32 2005 *************** *** 0 **** --- 1,33 ---- + ; RUN: llvm-as < %s | opt -condprop | llvm-dis | not grep phi + + int %test(uint %C, bool %Val) { + switch uint %C, label %T1 [ + uint 4, label %T2 + uint 17, label %T3 + ] + T1: + call void %a() + br label %Cont + T2: + call void %b() + br label %Cont + T3: + call void %c() + br label %Cont + + Cont: + ;; PHI becomes dead after threading T2 + %C2 = phi bool [%Val, %T1], [true, %T2], [%Val, %T3] + br bool %C2, label %L2, label %F2 + L2: + call void %d() + ret int 17 + F2: + call void %e() + ret int 1 + } + declare void %a() + declare void %b() + declare void %c() + declare void %d() + declare void %e() From natebegeman at mac.com Thu Aug 4 18:24:31 2005 From: natebegeman at mac.com (Nate Begeman) Date: Thu, 4 Aug 2005 18:24:31 -0500 Subject: [llvm-commits] CVS: llvm/include/llvm/Instructions.h Message-ID: <200508042324.SAA09560@zion.cs.uiuc.edu> Changes in directory llvm/include/llvm: Instructions.h updated: 1.24 -> 1.25 --- Log message: Fix a fixme in CondPropagate.cpp by moving a PhiNode optimization into BasicBlock's removePredecessor routine. This requires shuffling around the definition and implementation of hasContantValue from Utils.h,cpp into Instructions.h,cpp --- Diffs of the changes: (+5 -0) Instructions.h | 5 +++++ 1 files changed, 5 insertions(+) Index: llvm/include/llvm/Instructions.h diff -u llvm/include/llvm/Instructions.h:1.24 llvm/include/llvm/Instructions.h:1.25 --- llvm/include/llvm/Instructions.h:1.24 Sun Jun 19 09:46:20 2005 +++ llvm/include/llvm/Instructions.h Thu Aug 4 18:24:19 2005 @@ -804,6 +804,11 @@ return getIncomingValue(getBasicBlockIndex(BB)); } + /// hasConstantValue - If the specified PHI node always merges together the + /// same value, return the value, otherwise return null. + /// + Value *hasConstantValue(); + /// Methods for support type inquiry through isa, cast, and dyn_cast: static inline bool classof(const PHINode *) { return true; } static inline bool classof(const Instruction *I) { From natebegeman at mac.com Thu Aug 4 18:24:31 2005 From: natebegeman at mac.com (Nate Begeman) Date: Thu, 4 Aug 2005 18:24:31 -0500 Subject: [llvm-commits] CVS: llvm/lib/VMCore/BasicBlock.cpp Instructions.cpp Message-ID: <200508042324.SAA09566@zion.cs.uiuc.edu> Changes in directory llvm/lib/VMCore: BasicBlock.cpp updated: 1.64 -> 1.65 Instructions.cpp updated: 1.20 -> 1.21 --- Log message: Fix a fixme in CondPropagate.cpp by moving a PhiNode optimization into BasicBlock's removePredecessor routine. This requires shuffling around the definition and implementation of hasContantValue from Utils.h,cpp into Instructions.h,cpp --- Diffs of the changes: (+39 -1) BasicBlock.cpp | 10 +++++++++- Instructions.cpp | 30 ++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) Index: llvm/lib/VMCore/BasicBlock.cpp diff -u llvm/lib/VMCore/BasicBlock.cpp:1.64 llvm/lib/VMCore/BasicBlock.cpp:1.65 --- llvm/lib/VMCore/BasicBlock.cpp:1.64 Sat Apr 23 16:38:35 2005 +++ llvm/lib/VMCore/BasicBlock.cpp Thu Aug 4 18:24:19 2005 @@ -189,8 +189,16 @@ // Okay, now we know that we need to remove predecessor #pred_idx from all // PHI nodes. Iterate over each PHI node fixing them up PHINode *PN; - for (iterator II = begin(); (PN = dyn_cast(II)); ++II) + for (iterator II = begin(); (PN = dyn_cast(II)); ++II) { PN->removeIncomingValue(Pred, false); + // If all incoming values to the Phi are the same, we can replace the Phi + // with that value. + if (Value *PNV = PN->hasConstantValue()) + if (!isa(PNV)) { + PN->replaceAllUsesWith(PNV); + PN->eraseFromParent(); + } + } } } Index: llvm/lib/VMCore/Instructions.cpp diff -u llvm/lib/VMCore/Instructions.cpp:1.20 llvm/lib/VMCore/Instructions.cpp:1.21 --- llvm/lib/VMCore/Instructions.cpp:1.20 Sat Jun 18 13:34:52 2005 +++ llvm/lib/VMCore/Instructions.cpp Thu Aug 4 18:24:19 2005 @@ -132,6 +132,36 @@ OperandList = NewOps; } +/// hasConstantValue - If the specified PHI node always merges together the same +/// value, return the value, otherwise return null. +/// +Value *PHINode::hasConstantValue() { + // If the PHI node only has one incoming value, eliminate the PHI node... + if (getNumIncomingValues() == 1) + return getIncomingValue(0); + + // Otherwise if all of the incoming values are the same for the PHI, replace + // the PHI node with the incoming value. + // + Value *InVal = 0; + for (unsigned i = 0, e = getNumIncomingValues(); i != e; ++i) + if (getIncomingValue(i) != this && // Not the PHI node itself... + !isa(getIncomingValue(i))) + if (InVal && getIncomingValue(i) != InVal) + return 0; // Not the same, bail out. + else + InVal = getIncomingValue(i); + + // The only case that could cause InVal to be null is if we have a PHI node + // that only has entries for itself. In this case, there is no entry into the + // loop, so kill the PHI. + // + if (InVal == 0) InVal = UndefValue::get(getType()); + + // All of the incoming values are the same, return the value now. + return InVal; +} + //===----------------------------------------------------------------------===// // CallInst Implementation From natebegeman at mac.com Thu Aug 4 18:24:31 2005 From: natebegeman at mac.com (Nate Begeman) Date: Thu, 4 Aug 2005 18:24:31 -0500 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Utils/Local.cpp PromoteMemoryToRegister.cpp Message-ID: <200508042324.SAA09572@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Utils: Local.cpp updated: 1.41 -> 1.42 PromoteMemoryToRegister.cpp updated: 1.78 -> 1.79 --- Log message: Fix a fixme in CondPropagate.cpp by moving a PhiNode optimization into BasicBlock's removePredecessor routine. This requires shuffling around the definition and implementation of hasContantValue from Utils.h,cpp into Instructions.h,cpp --- Diffs of the changes: (+1 -36) Local.cpp | 34 ---------------------------------- PromoteMemoryToRegister.cpp | 3 +-- 2 files changed, 1 insertion(+), 36 deletions(-) Index: llvm/lib/Transforms/Utils/Local.cpp diff -u llvm/lib/Transforms/Utils/Local.cpp:1.41 llvm/lib/Transforms/Utils/Local.cpp:1.42 --- llvm/lib/Transforms/Utils/Local.cpp:1.41 Wed Jul 27 01:12:34 2005 +++ llvm/lib/Transforms/Utils/Local.cpp Thu Aug 4 18:24:19 2005 @@ -406,37 +406,3 @@ } return false; } - -//===----------------------------------------------------------------------===// -// PHI Instruction Simplification -// - -/// hasConstantValue - If the specified PHI node always merges together the same -/// value, return the value, otherwise return null. -/// -Value *llvm::hasConstantValue(PHINode *PN) { - // If the PHI node only has one incoming value, eliminate the PHI node... - if (PN->getNumIncomingValues() == 1) - return PN->getIncomingValue(0); - - // Otherwise if all of the incoming values are the same for the PHI, replace - // the PHI node with the incoming value. - // - Value *InVal = 0; - for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) - if (PN->getIncomingValue(i) != PN && // Not the PHI node itself... - !isa(PN->getIncomingValue(i))) - if (InVal && PN->getIncomingValue(i) != InVal) - return 0; // Not the same, bail out. - else - InVal = PN->getIncomingValue(i); - - // The only case that could cause InVal to be null is if we have a PHI node - // that only has entries for itself. In this case, there is no entry into the - // loop, so kill the PHI. - // - if (InVal == 0) InVal = UndefValue::get(PN->getType()); - - // All of the incoming values are the same, return the value now. - return InVal; -} Index: llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp diff -u llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp:1.78 llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp:1.79 --- llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp:1.78 Wed Jul 27 01:12:34 2005 +++ llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp Thu Aug 4 18:24:19 2005 @@ -24,7 +24,6 @@ #include "llvm/Analysis/Dominators.h" #include "llvm/Analysis/AliasSetTracker.h" #include "llvm/ADT/StringExtras.h" -#include "llvm/Transforms/Utils/Local.h" #include "llvm/Support/CFG.h" #include "llvm/Support/StableBasicBlockNumbering.h" #include @@ -348,7 +347,7 @@ PHINode *SomePHI = 0; for (unsigned i = 0, e = PNs.size(); i != e; ++i) if (PNs[i]) { - if (Value *V = hasConstantValue(PNs[i])) { + if (Value *V = PNs[i]->hasConstantValue()) { if (!isa(V) || dominates(cast(V), PNs[i])) { if (AST && isa(PNs[i]->getType())) AST->deleteValue(PNs[i]); From natebegeman at mac.com Thu Aug 4 18:24:32 2005 From: natebegeman at mac.com (Nate Begeman) Date: Thu, 4 Aug 2005 18:24:32 -0500 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/CondPropagate.cpp InstructionCombining.cpp LoopSimplify.cpp Message-ID: <200508042324.SAA09580@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Scalar: CondPropagate.cpp updated: 1.3 -> 1.4 InstructionCombining.cpp updated: 1.361 -> 1.362 LoopSimplify.cpp updated: 1.56 -> 1.57 --- Log message: Fix a fixme in CondPropagate.cpp by moving a PhiNode optimization into BasicBlock's removePredecessor routine. This requires shuffling around the definition and implementation of hasContantValue from Utils.h,cpp into Instructions.h,cpp --- Diffs of the changes: (+3 -15) CondPropagate.cpp | 11 ----------- InstructionCombining.cpp | 2 +- LoopSimplify.cpp | 5 ++--- 3 files changed, 3 insertions(+), 15 deletions(-) Index: llvm/lib/Transforms/Scalar/CondPropagate.cpp diff -u llvm/lib/Transforms/Scalar/CondPropagate.cpp:1.3 llvm/lib/Transforms/Scalar/CondPropagate.cpp:1.4 --- llvm/lib/Transforms/Scalar/CondPropagate.cpp:1.3 Thu Apr 21 18:45:12 2005 +++ llvm/lib/Transforms/Scalar/CondPropagate.cpp Thu Aug 4 18:24:19 2005 @@ -80,17 +80,6 @@ SimplifyPredecessors(SI); } - // See if we can fold any PHI nodes in this block now. - // FIXME: This would not be required if removePredecessor did this for us!! - PHINode *PN; - for (BasicBlock::iterator I = BB->begin(); (PN = dyn_cast(I++)); ) - if (Value *PNV = hasConstantValue(PN)) - if (!isa(PNV)) { - PN->replaceAllUsesWith(PNV); - PN->eraseFromParent(); - MadeChange = true; - } - // If possible, simplify the terminator of this block. if (ConstantFoldTerminator(BB)) MadeChange = true; Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.361 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.362 --- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.361 Tue Aug 2 14:16:58 2005 +++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Thu Aug 4 18:24:19 2005 @@ -4401,7 +4401,7 @@ // PHINode simplification // Instruction *InstCombiner::visitPHINode(PHINode &PN) { - if (Value *V = hasConstantValue(&PN)) { + if (Value *V = PN.hasConstantValue()) { // If V is an instruction, we have to be certain that it dominates PN. // However, because we don't have dom info, we can't do a perfect job. if (Instruction *I = dyn_cast(V)) { Index: llvm/lib/Transforms/Scalar/LoopSimplify.cpp diff -u llvm/lib/Transforms/Scalar/LoopSimplify.cpp:1.56 llvm/lib/Transforms/Scalar/LoopSimplify.cpp:1.57 --- llvm/lib/Transforms/Scalar/LoopSimplify.cpp:1.56 Thu Apr 21 18:45:12 2005 +++ llvm/lib/Transforms/Scalar/LoopSimplify.cpp Thu Aug 4 18:24:19 2005 @@ -41,7 +41,6 @@ #include "llvm/Analysis/Dominators.h" #include "llvm/Analysis/LoopInfo.h" #include "llvm/Support/CFG.h" -#include "llvm/Transforms/Utils/Local.h" #include "llvm/ADT/SetOperations.h" #include "llvm/ADT/SetVector.h" #include "llvm/ADT/Statistic.h" @@ -257,7 +256,7 @@ PN->addIncoming(InVal, NewBB); // Can we eliminate this phi node now? - if (Value *V = hasConstantValue(PN)) { + if (Value *V = PN->hasConstantValue()) { if (!isa(V) || getAnalysis().dominates(cast(V), PN)) { PN->replaceAllUsesWith(V); @@ -443,7 +442,7 @@ for (BasicBlock::iterator I = L->getHeader()->begin(); isa(I); ) { PHINode *PN = cast(I); ++I; - if (Value *V = hasConstantValue(PN)) + if (Value *V = PN->hasConstantValue()) if (!isa(V) || DS.dominates(cast(V), PN)) { // This is a degenerate PHI already, don't modify it! PN->replaceAllUsesWith(V); From natebegeman at mac.com Thu Aug 4 18:24:32 2005 From: natebegeman at mac.com (Nate Begeman) Date: Thu, 4 Aug 2005 18:24:32 -0500 Subject: [llvm-commits] CVS: llvm/include/llvm/Transforms/Utils/Local.h Message-ID: <200508042324.SAA09584@zion.cs.uiuc.edu> Changes in directory llvm/include/llvm/Transforms/Utils: Local.h updated: 1.18 -> 1.19 --- Log message: Fix a fixme in CondPropagate.cpp by moving a PhiNode optimization into BasicBlock's removePredecessor routine. This requires shuffling around the definition and implementation of hasContantValue from Utils.h,cpp into Instructions.h,cpp --- Diffs of the changes: (+0 -10) Local.h | 10 ---------- 1 files changed, 10 deletions(-) Index: llvm/include/llvm/Transforms/Utils/Local.h diff -u llvm/include/llvm/Transforms/Utils/Local.h:1.18 llvm/include/llvm/Transforms/Utils/Local.h:1.19 --- llvm/include/llvm/Transforms/Utils/Local.h:1.18 Thu Apr 21 15:59:05 2005 +++ llvm/include/llvm/Transforms/Utils/Local.h Thu Aug 4 18:24:19 2005 @@ -74,16 +74,6 @@ bool dceInstruction(BasicBlock::iterator &BBI); //===----------------------------------------------------------------------===// -// PHI Instruction Simplification -// - -/// hasConstantValue - If the specified PHI node always merges together the same -/// value, return the value, otherwise return null. -/// -Value *hasConstantValue(PHINode *PN); - - -//===----------------------------------------------------------------------===// // Control Flow Graph Restructuring... // From natebegeman at mac.com Thu Aug 4 18:50:54 2005 From: natebegeman at mac.com (Nate Begeman) Date: Thu, 4 Aug 2005 18:50:54 -0500 Subject: [llvm-commits] CVS: llvm/include/llvm/Instructions.h Message-ID: <200508042350.SAA09733@zion.cs.uiuc.edu> Changes in directory llvm/include/llvm: Instructions.h updated: 1.25 -> 1.26 --- Log message: Add an extra parameter that Chris requested --- Diffs of the changes: (+1 -1) Instructions.h | 2 +- 1 files changed, 1 insertion(+), 1 deletion(-) Index: llvm/include/llvm/Instructions.h diff -u llvm/include/llvm/Instructions.h:1.25 llvm/include/llvm/Instructions.h:1.26 --- llvm/include/llvm/Instructions.h:1.25 Thu Aug 4 18:24:19 2005 +++ llvm/include/llvm/Instructions.h Thu Aug 4 18:50:43 2005 @@ -807,7 +807,7 @@ /// hasConstantValue - If the specified PHI node always merges together the /// same value, return the value, otherwise return null. /// - Value *hasConstantValue(); + Value *hasConstantValue(bool AllowNonDominatingInstruction = false); /// Methods for support type inquiry through isa, cast, and dyn_cast: static inline bool classof(const PHINode *) { return true; } From natebegeman at mac.com Thu Aug 4 18:50:55 2005 From: natebegeman at mac.com (Nate Begeman) Date: Thu, 4 Aug 2005 18:50:55 -0500 Subject: [llvm-commits] CVS: llvm/lib/VMCore/Instructions.cpp Message-ID: <200508042350.SAA09737@zion.cs.uiuc.edu> Changes in directory llvm/lib/VMCore: Instructions.cpp updated: 1.21 -> 1.22 --- Log message: Add an extra parameter that Chris requested --- Diffs of the changes: (+1 -1) Instructions.cpp | 2 +- 1 files changed, 1 insertion(+), 1 deletion(-) Index: llvm/lib/VMCore/Instructions.cpp diff -u llvm/lib/VMCore/Instructions.cpp:1.21 llvm/lib/VMCore/Instructions.cpp:1.22 --- llvm/lib/VMCore/Instructions.cpp:1.21 Thu Aug 4 18:24:19 2005 +++ llvm/lib/VMCore/Instructions.cpp Thu Aug 4 18:50:43 2005 @@ -135,7 +135,7 @@ /// hasConstantValue - If the specified PHI node always merges together the same /// value, return the value, otherwise return null. /// -Value *PHINode::hasConstantValue() { +Value *PHINode::hasConstantValue(bool AllowNonDominatingInstruction) { // If the PHI node only has one incoming value, eliminate the PHI node... if (getNumIncomingValues() == 1) return getIncomingValue(0); From lattner at cs.uiuc.edu Thu Aug 4 19:49:18 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu, 4 Aug 2005 19:49:18 -0500 Subject: [llvm-commits] CVS: llvm/lib/VMCore/Instructions.cpp Message-ID: <200508050049.TAA09984@zion.cs.uiuc.edu> Changes in directory llvm/lib/VMCore: Instructions.cpp updated: 1.22 -> 1.23 --- Log message: Mark hasConstantValue as a const method --- Diffs of the changes: (+1 -1) Instructions.cpp | 2 +- 1 files changed, 1 insertion(+), 1 deletion(-) Index: llvm/lib/VMCore/Instructions.cpp diff -u llvm/lib/VMCore/Instructions.cpp:1.22 llvm/lib/VMCore/Instructions.cpp:1.23 --- llvm/lib/VMCore/Instructions.cpp:1.22 Thu Aug 4 18:50:43 2005 +++ llvm/lib/VMCore/Instructions.cpp Thu Aug 4 19:49:06 2005 @@ -135,7 +135,7 @@ /// hasConstantValue - If the specified PHI node always merges together the same /// value, return the value, otherwise return null. /// -Value *PHINode::hasConstantValue(bool AllowNonDominatingInstruction) { +Value *PHINode::hasConstantValue(bool AllowNonDominatingInstruction) const { // If the PHI node only has one incoming value, eliminate the PHI node... if (getNumIncomingValues() == 1) return getIncomingValue(0); From lattner at cs.uiuc.edu Thu Aug 4 19:49:18 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu, 4 Aug 2005 19:49:18 -0500 Subject: [llvm-commits] CVS: llvm/include/llvm/Instructions.h Message-ID: <200508050049.TAA09988@zion.cs.uiuc.edu> Changes in directory llvm/include/llvm: Instructions.h updated: 1.26 -> 1.27 --- Log message: Mark hasConstantValue as a const method --- Diffs of the changes: (+1 -1) Instructions.h | 2 +- 1 files changed, 1 insertion(+), 1 deletion(-) Index: llvm/include/llvm/Instructions.h diff -u llvm/include/llvm/Instructions.h:1.26 llvm/include/llvm/Instructions.h:1.27 --- llvm/include/llvm/Instructions.h:1.26 Thu Aug 4 18:50:43 2005 +++ llvm/include/llvm/Instructions.h Thu Aug 4 19:49:06 2005 @@ -807,7 +807,7 @@ /// hasConstantValue - If the specified PHI node always merges together the /// same value, return the value, otherwise return null. /// - Value *hasConstantValue(bool AllowNonDominatingInstruction = false); + Value *hasConstantValue(bool AllowNonDominatingInstruction = false) const; /// Methods for support type inquiry through isa, cast, and dyn_cast: static inline bool classof(const PHINode *) { return true; } From lattner at cs.uiuc.edu Thu Aug 4 19:57:06 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu, 4 Aug 2005 19:57:06 -0500 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/LoopSimplify.cpp Message-ID: <200508050057.TAA10064@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Scalar: LoopSimplify.cpp updated: 1.57 -> 1.58 --- Log message: This code can handle non-dominating instructions --- Diffs of the changes: (+1 -1) LoopSimplify.cpp | 2 +- 1 files changed, 1 insertion(+), 1 deletion(-) Index: llvm/lib/Transforms/Scalar/LoopSimplify.cpp diff -u llvm/lib/Transforms/Scalar/LoopSimplify.cpp:1.57 llvm/lib/Transforms/Scalar/LoopSimplify.cpp:1.58 --- llvm/lib/Transforms/Scalar/LoopSimplify.cpp:1.57 Thu Aug 4 18:24:19 2005 +++ llvm/lib/Transforms/Scalar/LoopSimplify.cpp Thu Aug 4 19:56:55 2005 @@ -256,7 +256,7 @@ PN->addIncoming(InVal, NewBB); // Can we eliminate this phi node now? - if (Value *V = PN->hasConstantValue()) { + if (Value *V = PN->hasConstantValue(true)) { if (!isa(V) || getAnalysis().dominates(cast(V), PN)) { PN->replaceAllUsesWith(V); From lattner at cs.uiuc.edu Thu Aug 4 19:57:56 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu, 4 Aug 2005 19:57:56 -0500 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp Message-ID: <200508050057.TAA10098@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Utils: PromoteMemoryToRegister.cpp updated: 1.79 -> 1.80 --- Log message: This code can handle non-dominating instructions --- Diffs of the changes: (+1 -1) PromoteMemoryToRegister.cpp | 2 +- 1 files changed, 1 insertion(+), 1 deletion(-) Index: llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp diff -u llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp:1.79 llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp:1.80 --- llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp:1.79 Thu Aug 4 18:24:19 2005 +++ llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp Thu Aug 4 19:57:45 2005 @@ -347,7 +347,7 @@ PHINode *SomePHI = 0; for (unsigned i = 0, e = PNs.size(); i != e; ++i) if (PNs[i]) { - if (Value *V = PNs[i]->hasConstantValue()) { + if (Value *V = PNs[i]->hasConstantValue(true)) { if (!isa(V) || dominates(cast(V), PNs[i])) { if (AST && isa(PNs[i]->getType())) AST->deleteValue(PNs[i]); From lattner at cs.uiuc.edu Thu Aug 4 20:00:07 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu, 4 Aug 2005 20:00:07 -0500 Subject: [llvm-commits] CVS: llvm/test/Regression/Transforms/CondProp/phisimplify2.ll Message-ID: <200508050100.UAA10214@zion.cs.uiuc.edu> Changes in directory llvm/test/Regression/Transforms/CondProp: phisimplify2.ll added (r1.1) --- Log message: new testcase that condprop should handle. The PHI node becomes useless after threading the branch, because both operands are the same value. --- Diffs of the changes: (+36 -0) phisimplify2.ll | 36 ++++++++++++++++++++++++++++++++++++ 1 files changed, 36 insertions(+) Index: llvm/test/Regression/Transforms/CondProp/phisimplify2.ll diff -c /dev/null llvm/test/Regression/Transforms/CondProp/phisimplify2.ll:1.1 *** /dev/null Thu Aug 4 20:00:06 2005 --- llvm/test/Regression/Transforms/CondProp/phisimplify2.ll Thu Aug 4 19:59:55 2005 *************** *** 0 **** --- 1,36 ---- + ; RUN: llvm-as < %s | opt -condprop | llvm-dis | not grep phi + + declare bool %foo() + + int %test(uint %C) { + %Val = call bool %foo() + switch uint %C, label %T1 [ + uint 4, label %T2 + uint 17, label %T3 + ] + T1: + call void %a() + br label %Cont + T2: + call void %b() + br label %Cont + T3: + call void %c() + br label %Cont + + Cont: + ;; PHI becomes dead after threading T2 + %C2 = phi bool [%Val, %T1], [true, %T2], [%Val, %T3] + br bool %C2, label %L2, label %F2 + L2: + call void %d() + ret int 17 + F2: + call void %e() + ret int 1 + } + declare void %a() + declare void %b() + declare void %c() + declare void %d() + declare void %e() From lattner at cs.uiuc.edu Thu Aug 4 20:01:10 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu, 4 Aug 2005 20:01:10 -0500 Subject: [llvm-commits] CVS: llvm/lib/VMCore/Instructions.cpp Message-ID: <200508050101.UAA10277@zion.cs.uiuc.edu> Changes in directory llvm/lib/VMCore: Instructions.cpp updated: 1.23 -> 1.24 --- Log message: Use the bool argument to hasConstantValue to decide whether the client is prepared to deal with return values that do not dominate the PHI. If we cannot prove that the result dominates the PHI node, do not return it if the client can't cope. --- Diffs of the changes: (+14 -2) Instructions.cpp | 16 ++++++++++++++-- 1 files changed, 14 insertions(+), 2 deletions(-) Index: llvm/lib/VMCore/Instructions.cpp diff -u llvm/lib/VMCore/Instructions.cpp:1.23 llvm/lib/VMCore/Instructions.cpp:1.24 --- llvm/lib/VMCore/Instructions.cpp:1.23 Thu Aug 4 19:49:06 2005 +++ llvm/lib/VMCore/Instructions.cpp Thu Aug 4 20:00:58 2005 @@ -144,9 +144,11 @@ // the PHI node with the incoming value. // Value *InVal = 0; + bool HasUndefInput = false; for (unsigned i = 0, e = getNumIncomingValues(); i != e; ++i) - if (getIncomingValue(i) != this && // Not the PHI node itself... - !isa(getIncomingValue(i))) + if (isa(getIncomingValue(i))) + HasUndefInput = true; + else if (getIncomingValue(i) != this) // Not the PHI node itself... if (InVal && getIncomingValue(i) != InVal) return 0; // Not the same, bail out. else @@ -158,6 +160,16 @@ // if (InVal == 0) InVal = UndefValue::get(getType()); + // If we have a PHI node like phi(X, undef, X), where X is defined by some + // instruction, we cannot always return X as the result of the PHI node. Only + // do this if X is not an instruction (thus it must dominate the PHI block), + // or if the client is prepared to deal with this possibility. + if (HasUndefInput && !AllowNonDominatingInstruction) + if (Instruction *IV = dyn_cast(InVal)) + // If it's in the entry block, it dominates everything. + if (IV->getParent() != &IV->getParent()->getParent()->front()) + return 0; // Cannot guarantee that InVal dominates this PHINode. + // All of the incoming values are the same, return the value now. return InVal; } From lattner at cs.uiuc.edu Thu Aug 4 20:02:15 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu, 4 Aug 2005 20:02:15 -0500 Subject: [llvm-commits] CVS: llvm/lib/VMCore/BasicBlock.cpp Message-ID: <200508050102.UAA10311@zion.cs.uiuc.edu> Changes in directory llvm/lib/VMCore: BasicBlock.cpp updated: 1.65 -> 1.66 --- Log message: Now that hasConstantValue is more careful w.r.t. returning values that only dominate the PHI node, this code can go away. This also makes passes more aggressive, e.g. implementing Transforms/CondProp/phisimplify2.ll --- Diffs of the changes: (+4 -5) BasicBlock.cpp | 9 ++++----- 1 files changed, 4 insertions(+), 5 deletions(-) Index: llvm/lib/VMCore/BasicBlock.cpp diff -u llvm/lib/VMCore/BasicBlock.cpp:1.65 llvm/lib/VMCore/BasicBlock.cpp:1.66 --- llvm/lib/VMCore/BasicBlock.cpp:1.65 Thu Aug 4 18:24:19 2005 +++ llvm/lib/VMCore/BasicBlock.cpp Thu Aug 4 20:02:04 2005 @@ -193,11 +193,10 @@ PN->removeIncomingValue(Pred, false); // If all incoming values to the Phi are the same, we can replace the Phi // with that value. - if (Value *PNV = PN->hasConstantValue()) - if (!isa(PNV)) { - PN->replaceAllUsesWith(PNV); - PN->eraseFromParent(); - } + if (Value *PNV = PN->hasConstantValue()) { + PN->replaceAllUsesWith(PNV); + PN->eraseFromParent(); + } } } } From lattner at cs.uiuc.edu Thu Aug 4 20:03:38 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu, 4 Aug 2005 20:03:38 -0500 Subject: [llvm-commits] CVS: llvm/lib/VMCore/Instructions.cpp Message-ID: <200508050103.UAA10348@zion.cs.uiuc.edu> Changes in directory llvm/lib/VMCore: Instructions.cpp updated: 1.24 -> 1.25 --- Log message: Invoke instructions do not dominate all successors --- Diffs of the changes: (+2 -1) Instructions.cpp | 3 ++- 1 files changed, 2 insertions(+), 1 deletion(-) Index: llvm/lib/VMCore/Instructions.cpp diff -u llvm/lib/VMCore/Instructions.cpp:1.24 llvm/lib/VMCore/Instructions.cpp:1.25 --- llvm/lib/VMCore/Instructions.cpp:1.24 Thu Aug 4 20:00:58 2005 +++ llvm/lib/VMCore/Instructions.cpp Thu Aug 4 20:03:27 2005 @@ -167,7 +167,8 @@ if (HasUndefInput && !AllowNonDominatingInstruction) if (Instruction *IV = dyn_cast(InVal)) // If it's in the entry block, it dominates everything. - if (IV->getParent() != &IV->getParent()->getParent()->front()) + if (IV->getParent() != &IV->getParent()->getParent()->front() || + isa(IV)) return 0; // Cannot guarantee that InVal dominates this PHINode. // All of the incoming values are the same, return the value now. From lattner at cs.uiuc.edu Thu Aug 4 20:04:41 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu, 4 Aug 2005 20:04:41 -0500 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp Message-ID: <200508050104.UAA10382@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Scalar: InstructionCombining.cpp updated: 1.362 -> 1.363 --- Log message: now that hasConstantValue defaults to only returning values that dominate the PHI node, this ugly code can vanish. --- Diffs of the changes: (+2 -19) InstructionCombining.cpp | 21 ++------------------- 1 files changed, 2 insertions(+), 19 deletions(-) Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.362 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.363 --- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.362 Thu Aug 4 18:24:19 2005 +++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Thu Aug 4 20:04:30 2005 @@ -4401,25 +4401,8 @@ // PHINode simplification // Instruction *InstCombiner::visitPHINode(PHINode &PN) { - if (Value *V = PN.hasConstantValue()) { - // If V is an instruction, we have to be certain that it dominates PN. - // However, because we don't have dom info, we can't do a perfect job. - if (Instruction *I = dyn_cast(V)) { - // We know that the instruction dominates the PHI if there are no undef - // values coming in. If the instruction is defined in the entry block, - // and is not an invoke, we know it is ok. - if (I->getParent() != &I->getParent()->getParent()->front() || - isa(I)) - for (unsigned i = 0, e = PN.getNumIncomingValues(); i != e; ++i) - if (isa(PN.getIncomingValue(i))) { - V = 0; - break; - } - } - - if (V) - return ReplaceInstUsesWith(PN, V); - } + if (Value *V = PN.hasConstantValue()) + return ReplaceInstUsesWith(PN, V); // If the only user of this instruction is a cast instruction, and all of the // incoming values are constants, change this PHI to merge together the casted From lattner at cs.uiuc.edu Thu Aug 4 20:30:23 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu, 4 Aug 2005 20:30:23 -0500 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp Message-ID: <200508050130.UAA10489@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Scalar: LoopStrengthReduce.cpp updated: 1.36 -> 1.37 --- Log message: Make sure to clean CastedPointers after casts are potentially deleted. This fixes LSR crashes on 301.apsi, 191.fma3d, and 189.lucas --- Diffs of the changes: (+1 -1) LoopStrengthReduce.cpp | 2 +- 1 files changed, 1 insertion(+), 1 deletion(-) Index: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp diff -u llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.36 llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.37 --- llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.36 Thu Aug 4 17:34:05 2005 +++ llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp Thu Aug 4 20:30:11 2005 @@ -106,7 +106,6 @@ for (LoopInfo::iterator I = LI->begin(), E = LI->end(); I != E; ++I) runOnLoop(*I); - CastedPointers.clear(); return Changed; } @@ -672,6 +671,7 @@ DeleteTriviallyDeadInstructions(DeadInsts); } + CastedPointers.clear(); IVUsesByStride.clear(); return; } From lattner at cs.uiuc.edu Fri Aug 5 01:20:59 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Fri, 5 Aug 2005 01:20:59 -0500 Subject: [llvm-commits] CVS: llvm-test/MultiSource/Applications/Makefile Message-ID: <200508050620.BAA11426@zion.cs.uiuc.edu> Changes in directory llvm-test/MultiSource/Applications: Makefile updated: 1.20 -> 1.21 --- Log message: No really, add hexxagonCVS: ---------------------------------------------------------------------- --- Diffs of the changes: (+1 -1) Makefile | 2 +- 1 files changed, 1 insertion(+), 1 deletion(-) Index: llvm-test/MultiSource/Applications/Makefile diff -u llvm-test/MultiSource/Applications/Makefile:1.20 llvm-test/MultiSource/Applications/Makefile:1.21 --- llvm-test/MultiSource/Applications/Makefile:1.20 Thu Aug 4 14:39:01 2005 +++ llvm-test/MultiSource/Applications/Makefile Fri Aug 5 01:20:48 2005 @@ -4,7 +4,7 @@ include $(LEVEL)/Makefile.config -PARALLEL_DIRS = Burg aha sgefa siod lambda-0.1.3 d spiff hbd treecc SPASS +PARALLEL_DIRS = Burg aha sgefa siod lambda-0.1.3 d spiff hbd treecc SPASS hexxagon # Obsequi uses Linux-only features; need to fix that ifeq ($(OS),Linux) From lattner at cs.uiuc.edu Fri Aug 5 10:34:24 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Fri, 5 Aug 2005 10:34:24 -0500 Subject: [llvm-commits] CVS: llvm/lib/VMCore/BasicBlock.cpp Message-ID: <200508051534.KAA10505@zion.cs.uiuc.edu> Changes in directory llvm/lib/VMCore: BasicBlock.cpp updated: 1.66 -> 1.67 --- Log message: Fix an iterator invalidation problem when we decide a phi has a constant value --- Diffs of the changes: (+2 -1) BasicBlock.cpp | 3 ++- 1 files changed, 2 insertions(+), 1 deletion(-) Index: llvm/lib/VMCore/BasicBlock.cpp diff -u llvm/lib/VMCore/BasicBlock.cpp:1.66 llvm/lib/VMCore/BasicBlock.cpp:1.67 --- llvm/lib/VMCore/BasicBlock.cpp:1.66 Thu Aug 4 20:02:04 2005 +++ llvm/lib/VMCore/BasicBlock.cpp Fri Aug 5 10:34:10 2005 @@ -189,7 +189,8 @@ // Okay, now we know that we need to remove predecessor #pred_idx from all // PHI nodes. Iterate over each PHI node fixing them up PHINode *PN; - for (iterator II = begin(); (PN = dyn_cast(II)); ++II) { + for (iterator II = begin(); (PN = dyn_cast(II)); ) { + ++II; PN->removeIncomingValue(Pred, false); // If all incoming values to the Phi are the same, we can replace the Phi // with that value. From lattner at cs.uiuc.edu Fri Aug 5 10:37:42 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Fri, 5 Aug 2005 10:37:42 -0500 Subject: [llvm-commits] CVS: llvm/lib/VMCore/Instructions.cpp Message-ID: <200508051537.KAA10590@zion.cs.uiuc.edu> Changes in directory llvm/lib/VMCore: Instructions.cpp updated: 1.25 -> 1.26 --- Log message: PHINode::hasConstantValue should never return the PHI itself, even if the PHI is its only operand. --- Diffs of the changes: (+5 -2) Instructions.cpp | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-) Index: llvm/lib/VMCore/Instructions.cpp diff -u llvm/lib/VMCore/Instructions.cpp:1.25 llvm/lib/VMCore/Instructions.cpp:1.26 --- llvm/lib/VMCore/Instructions.cpp:1.25 Thu Aug 4 20:03:27 2005 +++ llvm/lib/VMCore/Instructions.cpp Fri Aug 5 10:37:31 2005 @@ -138,8 +138,11 @@ Value *PHINode::hasConstantValue(bool AllowNonDominatingInstruction) const { // If the PHI node only has one incoming value, eliminate the PHI node... if (getNumIncomingValues() == 1) - return getIncomingValue(0); - + if (getIncomingValue(0) != this) // not X = phi X + return getIncomingValue(0); + else + return UndefValue::get(getType()); // Self cycle is dead. + // Otherwise if all of the incoming values are the same for the PHI, replace // the PHI node with the incoming value. // From lattner at cs.uiuc.edu Fri Aug 5 11:17:33 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Fri, 5 Aug 2005 11:17:33 -0500 Subject: [llvm-commits] CVS: llvm/lib/Target/PowerPC/PowerPCTargetMachine.cpp Message-ID: <200508051617.LAA18173@zion.cs.uiuc.edu> Changes in directory llvm/lib/Target/PowerPC: PowerPCTargetMachine.cpp updated: 1.59 -> 1.60 --- Log message: don't crash when running the PPC backend on non-ppc hosts without specifying a subtarget. --- Diffs of the changes: (+1 -3) PowerPCTargetMachine.cpp | 4 +--- 1 files changed, 1 insertion(+), 3 deletions(-) Index: llvm/lib/Target/PowerPC/PowerPCTargetMachine.cpp diff -u llvm/lib/Target/PowerPC/PowerPCTargetMachine.cpp:1.59 llvm/lib/Target/PowerPC/PowerPCTargetMachine.cpp:1.60 --- llvm/lib/Target/PowerPC/PowerPCTargetMachine.cpp:1.59 Thu Aug 4 15:49:48 2005 +++ llvm/lib/Target/PowerPC/PowerPCTargetMachine.cpp Fri Aug 5 11:17:22 2005 @@ -138,12 +138,10 @@ // Decide which asm printer to use. If the user has not specified one on // the command line, choose whichever one matches the default (current host). switch (PPCTarget) { - case TargetDefault: - assert(0 && "Default host has no asm printer!"); - break; case TargetAIX: PM.add(createAIXAsmPrinter(Out, *this)); break; + case TargetDefault: case TargetDarwin: PM.add(createDarwinAsmPrinter(Out, *this)); break; From lattner at cs.uiuc.edu Fri Aug 5 11:24:09 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Fri, 5 Aug 2005 11:24:09 -0500 Subject: [llvm-commits] CVS: llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp Message-ID: <200508051624.LAA18550@zion.cs.uiuc.edu> Changes in directory llvm/lib/CodeGen/SelectionDAG: LegalizeDAG.cpp updated: 1.153 -> 1.154 --- Log message: Fix a latent bug in the libcall inserter that was exposed by Nate's patch yesterday. This fixes whetstone and a bunch of programs in the External tests. --- Diffs of the changes: (+3 -6) LegalizeDAG.cpp | 9 +++------ 1 files changed, 3 insertions(+), 6 deletions(-) Index: llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp diff -u llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:1.153 llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:1.154 --- llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:1.153 Thu Aug 4 16:43:28 2005 +++ llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp Fri Aug 5 11:23:57 2005 @@ -1478,7 +1478,6 @@ case ISD::FSIN: case ISD::FCOS: { MVT::ValueType VT = Node->getValueType(0); - Type *T = VT == MVT::f32 ? Type::FloatTy : Type::DoubleTy; const char *FnName = 0; switch(Node->getOpcode()) { case ISD::FSQRT: FnName = VT == MVT::f32 ? "sqrtf" : "sqrt"; break; @@ -2263,7 +2262,7 @@ /// Found. static void FindLatestCallSeqStart(SDNode *Node, SDNode *&Found) { if (Node->getNodeDepth() <= Found->getNodeDepth()) return; - + // If we found an CALLSEQ_START, we already know this node occurs later // than the Found node. Just remember this node and return. if (Node->getOpcode() == ISD::CALLSEQ_START) { @@ -2323,8 +2322,7 @@ assert(TheChain.getValueType() == MVT::Other && "Is not a token chain!"); for (SDNode::use_iterator UI = Node->use_begin(), - E = Node->use_end(); ; ++UI) { - assert(UI != E && "Didn't find a user of the tokchain, no CALLSEQ_END!"); + E = Node->use_end(); UI != E; ++UI) { // Make sure to only follow users of our token chain. SDNode *User = *UI; @@ -2333,8 +2331,7 @@ if (SDNode *Result = FindCallSeqEnd(User)) return Result; } - assert(0 && "Unreachable"); - abort(); + return 0; } /// FindCallSeqStart - Given a chained node that is part of a call sequence, From lattner at cs.uiuc.edu Fri Aug 5 11:55:42 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Fri, 5 Aug 2005 11:55:42 -0500 Subject: [llvm-commits] CVS: llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp Message-ID: <200508051655.LAA21719@zion.cs.uiuc.edu> Changes in directory llvm/lib/CodeGen/SelectionDAG: SelectionDAG.cpp updated: 1.127 -> 1.128 --- Log message: Fix a use-of-dangling-pointer bug, from the introduction of SrcValue's. --- Diffs of the changes: (+5 -0) SelectionDAG.cpp | 5 +++++ 1 files changed, 5 insertions(+) Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp diff -u llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1.127 llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1.128 --- llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1.127 Tue Aug 2 14:26:06 2005 +++ llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp Fri Aug 5 11:55:31 2005 @@ -215,6 +215,11 @@ case ISD::VALUETYPE: ValueTypeNodes[cast(N)->getVT()] = 0; break; + case ISD::SRCVALUE: { + SrcValueSDNode *SVN = cast(N); + ValueNodes.erase(std::make_pair(SVN->getValue(), SVN->getOffset())); + break; + } case ISD::LOAD: Loads.erase(std::make_pair(N->getOperand(1), std::make_pair(N->getOperand(0), From lattner at cs.uiuc.edu Fri Aug 5 13:10:38 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Fri, 5 Aug 2005 13:10:38 -0500 Subject: [llvm-commits] CVS: llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp Message-ID: <200508051810.NAA22083@zion.cs.uiuc.edu> Changes in directory llvm/lib/CodeGen/SelectionDAG: LegalizeDAG.cpp updated: 1.154 -> 1.155 --- Log message: Change FindEarliestCallSeqEnd (used by libcall insertion) to use a set to avoid revisiting nodes more than once. This eliminates a source of potentially exponential behavior. For a small function in 191.fma3d (hexah_stress_divergence_), this speeds up isel from taking > 20mins to taking 0.07s. --- Diffs of the changes: (+9 -5) LegalizeDAG.cpp | 14 +++++++++----- 1 files changed, 9 insertions(+), 5 deletions(-) Index: llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp diff -u llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:1.154 llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:1.155 --- llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp:1.154 Fri Aug 5 11:23:57 2005 +++ llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp Fri Aug 5 13:10:27 2005 @@ -21,6 +21,7 @@ #include "llvm/CallingConv.h" #include "llvm/Constants.h" #include +#include using namespace llvm; //===----------------------------------------------------------------------===// @@ -2285,8 +2286,10 @@ /// FindEarliestCallSeqEnd - Scan down the dag to find the earliest (lowest /// NodeDepth) node that is an CallSeqEnd operation and occurs more recent /// than Found. -static void FindEarliestCallSeqEnd(SDNode *Node, SDNode *&Found) { - if (Found && Node->getNodeDepth() >= Found->getNodeDepth()) return; +static void FindEarliestCallSeqEnd(SDNode *Node, SDNode *&Found, + std::set &Visited) { + if ((Found && Node->getNodeDepth() >= Found->getNodeDepth()) || + !Visited.insert(Node).second) return; // If we found an CALLSEQ_END, we already know this node occurs earlier // than the Found node. Just remember this node and return. @@ -2299,10 +2302,10 @@ SDNode::use_iterator UI = Node->use_begin(), E = Node->use_end(); if (UI == E) return; for (--E; UI != E; ++UI) - FindEarliestCallSeqEnd(*UI, Found); + FindEarliestCallSeqEnd(*UI, Found, Visited); // Tail recurse for the last iteration. - FindEarliestCallSeqEnd(*UI, Found); + FindEarliestCallSeqEnd(*UI, Found, Visited); } /// FindCallSeqEnd - Given a chained node that is part of a call sequence, @@ -2372,7 +2375,8 @@ // Finally, find the first call that this must come before, first we find the // CallSeqEnd that ends the call. OutChain = 0; - FindEarliestCallSeqEnd(OpNode, OutChain); + std::set Visited; + FindEarliestCallSeqEnd(OpNode, OutChain, Visited); // If we found one, translate from the adj up to the callseq_start. if (OutChain) From lattner at cs.uiuc.edu Fri Aug 5 14:18:45 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Fri, 5 Aug 2005 14:18:45 -0500 Subject: [llvm-commits] CVS: llvm/lib/Target/PowerPC/README.txt Message-ID: <200508051918.OAA22368@zion.cs.uiuc.edu> Changes in directory llvm/lib/Target/PowerPC: README.txt updated: 1.25 -> 1.26 --- Log message: add a note --- Diffs of the changes: (+3 -0) README.txt | 3 +++ 1 files changed, 3 insertions(+) Index: llvm/lib/Target/PowerPC/README.txt diff -u llvm/lib/Target/PowerPC/README.txt:1.25 llvm/lib/Target/PowerPC/README.txt:1.26 --- llvm/lib/Target/PowerPC/README.txt:1.25 Wed Jul 27 01:06:29 2005 +++ llvm/lib/Target/PowerPC/README.txt Fri Aug 5 14:18:32 2005 @@ -8,6 +8,9 @@ la r2, lo16(l2__ZTV4Cell)(r2) addi r2, r2, 8 +* Support 'update' load/store instructions. These are cracked on the G5, but + are still a codesize win. + * should hint to the branch select pass that it doesn't need to print the second unconditional branch, so we don't end up with things like: b .LBBl42__2E_expand_function_8_674 ; loopentry.24 From lattner at cs.uiuc.edu Fri Aug 5 14:47:51 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Fri, 5 Aug 2005 14:47:51 -0500 Subject: [llvm-commits] CVS: llvm/test/Regression/Transforms/LoopStrengthReduce/exit_compare_live_range.ll related_indvars.ll Message-ID: <200508051947.OAA22529@zion.cs.uiuc.edu> Changes in directory llvm/test/Regression/Transforms/LoopStrengthReduce: exit_compare_live_range.ll added (r1.1) related_indvars.ll added (r1.1) --- Log message: two simple testcases loopreduce should handle but does not yet currently --- Diffs of the changes: (+50 -0) exit_compare_live_range.ll | 21 +++++++++++++++++++++ related_indvars.ll | 29 +++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) Index: llvm/test/Regression/Transforms/LoopStrengthReduce/exit_compare_live_range.ll diff -c /dev/null llvm/test/Regression/Transforms/LoopStrengthReduce/exit_compare_live_range.ll:1.1 *** /dev/null Fri Aug 5 14:47:49 2005 --- llvm/test/Regression/Transforms/LoopStrengthReduce/exit_compare_live_range.ll Fri Aug 5 14:47:39 2005 *************** *** 0 **** --- 1,21 ---- + ; Make sure that the compare instruction occurs after the increment to avoid + ; having overlapping live ranges that result in copies. We want the setcc instruction + ; immediately before the conditional branch. + ; + ; RUN: llvm-as < %s | opt -loop-reduce | llvm-dis | %prcontext 'br bool' 1 | grep set + ; XFAIL: * + + void %foo(float* %D, uint %E) { + entry: + br label %no_exit + + no_exit: + %indvar = phi uint [ 0, %entry ], [ %indvar.next, %no_exit ] + volatile store float 0.0, float* %D + %indvar.next = add uint %indvar, 1 ; [#uses=2] + %exitcond = seteq uint %indvar.next, %E ; [#uses=1] + br bool %exitcond, label %loopexit, label %no_exit + + loopexit: + ret void + } Index: llvm/test/Regression/Transforms/LoopStrengthReduce/related_indvars.ll diff -c /dev/null llvm/test/Regression/Transforms/LoopStrengthReduce/related_indvars.ll:1.1 *** /dev/null Fri Aug 5 14:47:51 2005 --- llvm/test/Regression/Transforms/LoopStrengthReduce/related_indvars.ll Fri Aug 5 14:47:39 2005 *************** *** 0 **** --- 1,29 ---- + ; RUN: llvm-as < %s | opt -loop-reduce | llvm-dis | grep phi | wc -l | grep 1 + + ; This should only result in one PHI node! + ; XFAIL: * + + ; void foo(double *D, double *E, double F) { + ; while (D != E) + ; *D++ = F; + ; } + + void %foo(double* %D, double* %E, double %F) { + entry: + %tmp.24 = seteq double* %D, %E ; [#uses=1] + br bool %tmp.24, label %return, label %no_exit + + no_exit: ; preds = %no_exit, %entry + %indvar = phi uint [ 0, %entry ], [ %indvar.next, %no_exit ] ; [#uses=3] + %D_addr.0.0.rec = cast uint %indvar to int ; [#uses=1] + %D_addr.0.0 = getelementptr double* %D, uint %indvar ; [#uses=1] + %inc.rec = add int %D_addr.0.0.rec, 1 ; [#uses=1] + %inc = getelementptr double* %D, int %inc.rec ; [#uses=1] + store double %F, double* %D_addr.0.0 + %tmp.2 = seteq double* %inc, %E ; [#uses=1] + %indvar.next = add uint %indvar, 1 ; [#uses=1] + br bool %tmp.2, label %return, label %no_exit + + return: ; preds = %no_exit, %entry + ret void + } From lattner at cs.uiuc.edu Fri Aug 5 14:48:40 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Fri, 5 Aug 2005 14:48:40 -0500 Subject: [llvm-commits] CVS: llvm/test/TestRunner.sh Message-ID: <200508051948.OAA22589@zion.cs.uiuc.edu> Changes in directory llvm/test: TestRunner.sh updated: 1.9 -> 1.10 --- Log message: teach TestRunner about prcontext --- Diffs of the changes: (+1 -1) TestRunner.sh | 2 +- 1 files changed, 1 insertion(+), 1 deletion(-) Index: llvm/test/TestRunner.sh diff -u llvm/test/TestRunner.sh:1.9 llvm/test/TestRunner.sh:1.10 --- llvm/test/TestRunner.sh:1.9 Mon Jan 3 16:26:38 2005 +++ llvm/test/TestRunner.sh Fri Aug 5 14:48:29 2005 @@ -30,7 +30,7 @@ ulimit -t 40 SCRIPT=$OUTPUT.script -grep 'RUN:' $FILENAME | sed "s|^.*RUN:\(.*\)$|\1|g;s|%s|$SUBST|g;s|%llvmgcc|llvm-gcc|g;s|%llvmgxx|llvm-g++|g" > $SCRIPT +grep 'RUN:' $FILENAME | sed "s|^.*RUN:\(.*\)$|\1|g;s|%s|$SUBST|g;s|%llvmgcc|llvm-gcc|g;s|%llvmgxx|llvm-g++|g;s|%prcontext|prcontext.tcl|g" > $SCRIPT /bin/sh $SCRIPT > $OUTPUT 2>&1 || ( From lattner at cs.uiuc.edu Fri Aug 5 16:24:23 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Fri, 5 Aug 2005 16:24:23 -0500 Subject: [llvm-commits] CVS: llvm-test/Makefile.programs Message-ID: <200508052124.QAA23176@zion.cs.uiuc.edu> Changes in directory llvm-test: Makefile.programs updated: 1.159 -> 1.160 --- Log message: Switch to testing LSR for llc-beta on PowerPC --- Diffs of the changes: (+2 -1) Makefile.programs | 3 ++- 1 files changed, 2 insertions(+), 1 deletion(-) Index: llvm-test/Makefile.programs diff -u llvm-test/Makefile.programs:1.159 llvm-test/Makefile.programs:1.160 --- llvm-test/Makefile.programs:1.159 Thu Aug 4 07:42:52 2005 +++ llvm-test/Makefile.programs Fri Aug 5 16:24:11 2005 @@ -187,7 +187,8 @@ endif#DISABLE_DIFFS ifeq ($(ARCH),PowerPC) -LLCBETAOPTION := -enable-gpopt +LLCBETAOPTION := -enable-lsr-for-ppc +#-enable-gpopt endif ifeq ($(ARCH),Alpha) LLCBETAOPTION := -enable-alpha-ftoi -enable-lsr-for-alpha From lattner at cs.uiuc.edu Fri Aug 5 16:25:24 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Fri, 5 Aug 2005 16:25:24 -0500 Subject: [llvm-commits] CVS: llvm/lib/Target/PowerPC/PowerPCSubtarget.cpp Message-ID: <200508052125.QAA23246@zion.cs.uiuc.edu> Changes in directory llvm/lib/Target/PowerPC: PowerPCSubtarget.cpp updated: 1.1 -> 1.2 --- Log message: Enable gp optimizations by default when available, even when a target triple is available, since the target triple doesn't specify whether to use gpopts or not. --- Diffs of the changes: (+3 -0) PowerPCSubtarget.cpp | 3 +++ 1 files changed, 3 insertions(+) Index: llvm/lib/Target/PowerPC/PowerPCSubtarget.cpp diff -u llvm/lib/Target/PowerPC/PowerPCSubtarget.cpp:1.1 llvm/lib/Target/PowerPC/PowerPCSubtarget.cpp:1.2 --- llvm/lib/Target/PowerPC/PowerPCSubtarget.cpp:1.1 Thu Aug 4 02:12:08 2005 +++ llvm/lib/Target/PowerPC/PowerPCSubtarget.cpp Fri Aug 5 16:25:13 2005 @@ -43,6 +43,9 @@ const std::string& TT = M.getTargetTriple(); if (TT.length() > 5) { isDarwin = TT.find("darwin") != std::string::npos; +#if defined(__APPLE__) + isGigaProcessor = IsGP(); +#endif } else if (TT.empty()) { #if defined(_POWER) isAIX = true; From lattner at cs.uiuc.edu Fri Aug 5 16:53:32 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Fri, 5 Aug 2005 16:53:32 -0500 Subject: [llvm-commits] CVS: llvm/include/llvm/Target/TargetMachine.h Message-ID: <200508052153.QAA23931@zion.cs.uiuc.edu> Changes in directory llvm/include/llvm/Target: TargetMachine.h updated: 1.56 -> 1.57 --- Log message: Since getSubtarget() always provides a const Subtarget, dont' require the user to pass it in. Also, since it always returns a non-null pointer, make it return a reference instead for easier use. --- Diffs of the changes: (+3 -3) TargetMachine.h | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) Index: llvm/include/llvm/Target/TargetMachine.h diff -u llvm/include/llvm/Target/TargetMachine.h:1.56 llvm/include/llvm/Target/TargetMachine.h:1.57 --- llvm/include/llvm/Target/TargetMachine.h:1.56 Wed Jul 27 00:53:43 2005 +++ llvm/include/llvm/Target/TargetMachine.h Fri Aug 5 16:53:21 2005 @@ -105,11 +105,11 @@ /// getSubtarget - This method returns a pointer to the specified type of /// TargetSubtarget. In debug builds, it verifies that the object being /// returned is of the correct type. - template STC *getSubtarget() const { + template const STC &getSubtarget() const { const TargetSubtarget *TST = getSubtargetImpl(); - assert(getSubtargetImpl() && dynamic_cast(TST) && + assert(TST && dynamic_cast(TST) && "Not the right kind of subtarget!"); - return (STC*)TST; + return *static_cast(TST); } /// getRegisterInfo - If register information is available, return it. If From lattner at cs.uiuc.edu Fri Aug 5 16:54:39 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Fri, 5 Aug 2005 16:54:39 -0500 Subject: [llvm-commits] CVS: llvm/lib/Target/X86/X86ISelPattern.cpp Message-ID: <200508052154.QAA24085@zion.cs.uiuc.edu> Changes in directory llvm/lib/Target/X86: X86ISelPattern.cpp updated: 1.164 -> 1.165 --- Log message: adjust to change in getSubtarget() api --- Diffs of the changes: (+1 -1) X86ISelPattern.cpp | 2 +- 1 files changed, 1 insertion(+), 1 deletion(-) Index: llvm/lib/Target/X86/X86ISelPattern.cpp diff -u llvm/lib/Target/X86/X86ISelPattern.cpp:1.164 llvm/lib/Target/X86/X86ISelPattern.cpp:1.165 --- llvm/lib/Target/X86/X86ISelPattern.cpp:1.164 Wed Aug 3 18:26:28 2005 +++ llvm/lib/Target/X86/X86ISelPattern.cpp Fri Aug 5 16:54:27 2005 @@ -1092,7 +1092,7 @@ const X86Subtarget *Subtarget; public: ISel(TargetMachine &TM) : SelectionDAGISel(X86Lowering), X86Lowering(TM) { - Subtarget = TM.getSubtarget(); + Subtarget = &TM.getSubtarget(); } virtual const char *getPassName() const { From lattner at cs.uiuc.edu Fri Aug 5 17:05:14 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Fri, 5 Aug 2005 17:05:14 -0500 Subject: [llvm-commits] CVS: llvm/lib/Target/PowerPC/PPC32ISelPattern.cpp PowerPC.h PowerPCAsmPrinter.cpp PowerPCSubtarget.cpp PowerPCSubtarget.h PowerPCTargetMachine.cpp Message-ID: <200508052205.RAA24646@zion.cs.uiuc.edu> Changes in directory llvm/lib/Target/PowerPC: PPC32ISelPattern.cpp updated: 1.114 -> 1.115 PowerPC.h updated: 1.18 -> 1.19 PowerPCAsmPrinter.cpp updated: 1.85 -> 1.86 PowerPCSubtarget.cpp updated: 1.2 -> 1.3 PowerPCSubtarget.h updated: 1.1 -> 1.2 PowerPCTargetMachine.cpp updated: 1.60 -> 1.61 --- Log message: Consolidate the GPOpt stuff to all use the Subtarget, instead of still depending on the command line option. Now the command line option just sets the subtarget as appropriate. G5 opts will now default to on on G5-enabled nightly testers among other machines. --- Diffs of the changes: (+48 -42) PPC32ISelPattern.cpp | 7 +++++-- PowerPC.h | 1 - PowerPCAsmPrinter.cpp | 4 +++- PowerPCSubtarget.cpp | 37 +++++++++++++++++++++++++++---------- PowerPCSubtarget.h | 16 +++++++++------- PowerPCTargetMachine.cpp | 25 ++++--------------------- 6 files changed, 48 insertions(+), 42 deletions(-) Index: llvm/lib/Target/PowerPC/PPC32ISelPattern.cpp diff -u llvm/lib/Target/PowerPC/PPC32ISelPattern.cpp:1.114 llvm/lib/Target/PowerPC/PPC32ISelPattern.cpp:1.115 --- llvm/lib/Target/PowerPC/PPC32ISelPattern.cpp:1.114 Wed Aug 3 12:29:52 2005 +++ llvm/lib/Target/PowerPC/PPC32ISelPattern.cpp Fri Aug 5 17:05:03 2005 @@ -96,7 +96,7 @@ setOperationAction(ISD::SREM , MVT::f32, Expand); // If we're enabling GP optimizations, use hardware square root - if (!GPOPT) { + if (!TM.getSubtarget().isGigaProcessor()) { setOperationAction(ISD::FSQRT, MVT::f64, Expand); setOperationAction(ISD::FSQRT, MVT::f32, Expand); } @@ -536,6 +536,7 @@ Statistic<>Recorded("ppc-codegen", "Number of recording ops emitted"); Statistic<>FusedFP("ppc-codegen", "Number of fused fp operations"); Statistic<>FrameOff("ppc-codegen", "Number of frame idx offsets collapsed"); + //===--------------------------------------------------------------------===// /// ISel - PPC32 specific code to select PPC32 machine instructions for /// SelectionDAG operations. @@ -929,7 +930,9 @@ void ISel::MoveCRtoGPR(unsigned CCReg, bool Inv, unsigned Idx, unsigned Result){ unsigned IntCR = MakeReg(MVT::i32); BuildMI(BB, PPC::MCRF, 1, PPC::CR7).addReg(CCReg); - BuildMI(BB, GPOPT ? PPC::MFOCRF : PPC::MFCR, 1, IntCR).addReg(PPC::CR7); + bool GPOpt = + TLI.getTargetMachine().getSubtarget().isGigaProcessor(); + BuildMI(BB, GPOpt ? PPC::MFOCRF : PPC::MFCR, 1, IntCR).addReg(PPC::CR7); if (Inv) { unsigned Tmp1 = MakeReg(MVT::i32); BuildMI(BB, PPC::RLWINM, 4, Tmp1).addReg(IntCR).addImm(32-(3-Idx)) Index: llvm/lib/Target/PowerPC/PowerPC.h diff -u llvm/lib/Target/PowerPC/PowerPC.h:1.18 llvm/lib/Target/PowerPC/PowerPC.h:1.19 --- llvm/lib/Target/PowerPC/PowerPC.h:1.18 Thu Aug 4 15:49:48 2005 +++ llvm/lib/Target/PowerPC/PowerPC.h Fri Aug 5 17:05:03 2005 @@ -33,7 +33,6 @@ FunctionPass *createDarwinAsmPrinter(std::ostream &OS, TargetMachine &TM); FunctionPass *createAIXAsmPrinter(std::ostream &OS, TargetMachine &TM); -extern bool GPOPT; extern bool PICEnabled; extern PPCTargetEnum PPCTarget; } // end namespace llvm; Index: llvm/lib/Target/PowerPC/PowerPCAsmPrinter.cpp diff -u llvm/lib/Target/PowerPC/PowerPCAsmPrinter.cpp:1.85 llvm/lib/Target/PowerPC/PowerPCAsmPrinter.cpp:1.86 --- llvm/lib/Target/PowerPC/PowerPCAsmPrinter.cpp:1.85 Thu Aug 4 16:04:09 2005 +++ llvm/lib/Target/PowerPC/PowerPCAsmPrinter.cpp Fri Aug 5 17:05:03 2005 @@ -19,6 +19,7 @@ #define DEBUG_TYPE "asmprinter" #include "PowerPC.h" #include "PowerPCTargetMachine.h" +#include "PowerPCSubtarget.h" #include "llvm/Constants.h" #include "llvm/DerivedTypes.h" #include "llvm/Module.h" @@ -440,7 +441,8 @@ } bool DarwinAsmPrinter::doInitialization(Module &M) { - if (GPOPT) O << "\t.machine ppc970\n"; + if (TM.getSubtarget().isGigaProcessor()) + O << "\t.machine ppc970\n"; AsmPrinter::doInitialization(M); return false; } Index: llvm/lib/Target/PowerPC/PowerPCSubtarget.cpp diff -u llvm/lib/Target/PowerPC/PowerPCSubtarget.cpp:1.2 llvm/lib/Target/PowerPC/PowerPCSubtarget.cpp:1.3 --- llvm/lib/Target/PowerPC/PowerPCSubtarget.cpp:1.2 Fri Aug 5 16:25:13 2005 +++ llvm/lib/Target/PowerPC/PowerPCSubtarget.cpp Fri Aug 5 17:05:03 2005 @@ -12,7 +12,23 @@ //===----------------------------------------------------------------------===// #include "PowerPCSubtarget.h" +#include "PowerPC.h" #include "llvm/Module.h" +#include "llvm/Support/CommandLine.h" +using namespace llvm; +PPCTargetEnum llvm::PPCTarget = TargetDefault; + +namespace llvm { + cl::opt + PPCTargetArg(cl::desc("Force generation of code for a specific PPC target:"), + cl::values( + clEnumValN(TargetAIX, "aix", " Enable AIX codegen"), + clEnumValN(TargetDarwin,"darwin"," Enable Darwin codegen"), + clEnumValEnd), + cl::location(PPCTarget), cl::init(TargetDefault)); + cl::opt EnableGPOPT("enable-gpopt", cl::Hidden, + cl::desc("Enable optimizations for GP cpus")); +} #if defined(__APPLE__) #include @@ -33,25 +49,26 @@ } #endif -using namespace llvm; - PPCSubtarget::PPCSubtarget(const Module &M) - : TargetSubtarget(), stackAlignment(16), isGigaProcessor(false), isAIX(false), - isDarwin(false) { - // Set the boolean corresponding to the current target triple, or the default + : StackAlignment(16), IsGigaProcessor(false), IsAIX(false), IsDarwin(false) { + + // Set the boolean corresponding to the current target triple, or the default // if one cannot be determined, to true. const std::string& TT = M.getTargetTriple(); if (TT.length() > 5) { - isDarwin = TT.find("darwin") != std::string::npos; + IsDarwin = TT.find("darwin") != std::string::npos; #if defined(__APPLE__) - isGigaProcessor = IsGP(); + IsGigaProcessor = IsGP(); #endif } else if (TT.empty()) { #if defined(_POWER) - isAIX = true; + IsAIX = true; #elif defined(__APPLE__) - isDarwin = true; - isGigaProcessor = IsGP(); + IsDarwin = true; + IsGigaProcessor = IsGP(); #endif } + + // If GP opts are forced on by the commandline, do so now. + if (EnableGPOPT) IsGigaProcessor = true; } Index: llvm/lib/Target/PowerPC/PowerPCSubtarget.h diff -u llvm/lib/Target/PowerPC/PowerPCSubtarget.h:1.1 llvm/lib/Target/PowerPC/PowerPCSubtarget.h:1.2 --- llvm/lib/Target/PowerPC/PowerPCSubtarget.h:1.1 Thu Aug 4 02:12:08 2005 +++ llvm/lib/Target/PowerPC/PowerPCSubtarget.h Fri Aug 5 17:05:03 2005 @@ -23,12 +23,12 @@ protected: /// stackAlignment - The minimum alignment known to hold of the stack frame on /// entry to the function and which must be maintained by every function. - unsigned stackAlignment; + unsigned StackAlignment; /// Used by the ISel to turn in optimizations for POWER4-derived architectures - bool isGigaProcessor; - bool isAIX; - bool isDarwin; + bool IsGigaProcessor; + bool IsAIX; + bool IsDarwin; public: /// This constructor initializes the data members to match that /// of the specified module. @@ -38,10 +38,12 @@ /// getStackAlignment - Returns the minimum alignment known to hold of the /// stack frame on entry to the function and which must be maintained by every /// function for this subtarget. - unsigned getStackAlignment() const { return stackAlignment; } + unsigned getStackAlignment() const { return StackAlignment; } - bool IsAIX() const { return isAIX; } - bool IsDarwin() const { return isDarwin; } + bool isAIX() const { return IsAIX; } + bool isDarwin() const { return IsDarwin; } + + bool isGigaProcessor() const { return IsGigaProcessor; } }; } // End llvm namespace Index: llvm/lib/Target/PowerPC/PowerPCTargetMachine.cpp diff -u llvm/lib/Target/PowerPC/PowerPCTargetMachine.cpp:1.60 llvm/lib/Target/PowerPC/PowerPCTargetMachine.cpp:1.61 --- llvm/lib/Target/PowerPC/PowerPCTargetMachine.cpp:1.60 Fri Aug 5 11:17:22 2005 +++ llvm/lib/Target/PowerPC/PowerPCTargetMachine.cpp Fri Aug 5 17:05:03 2005 @@ -30,25 +30,8 @@ #include using namespace llvm; -bool llvm::GPOPT = false; -PPCTargetEnum llvm::PPCTarget = TargetDefault; - -namespace llvm { - cl::opt - PPCTargetArg( - cl::desc("Force generation of code for a specific PPC target:"), - cl::values( - clEnumValN(TargetAIX, "aix", " Enable AIX codegen"), - clEnumValN(TargetDarwin,"darwin"," Enable Darwin codegen"), - clEnumValEnd), - cl::location(PPCTarget), cl::init(TargetDefault)); - cl::opt EnablePPCLSR("enable-lsr-for-ppc", - cl::desc("Enable LSR for PPC (beta)"), - cl::Hidden); - cl::opt EnableGPOPT("enable-gpopt", cl::Hidden, - cl::location(GPOPT), - cl::desc("Enable optimizations for GP cpus")); -} +static cl::opt EnablePPCLSR("enable-lsr-for-ppc", cl::Hidden, + cl::desc("Enable LSR for PPC (beta)")); namespace { const std::string PPC32ID = "PowerPC/32bit"; @@ -71,8 +54,8 @@ const PowerPCFrameInfo &TFI) : TargetMachine(name, IL, TD), FrameInfo(TFI), Subtarget(M) { if (TargetDefault == PPCTarget) { - if (Subtarget.IsAIX()) PPCTarget = TargetAIX; - if (Subtarget.IsDarwin()) PPCTarget = TargetDarwin; + if (Subtarget.isAIX()) PPCTarget = TargetAIX; + if (Subtarget.isDarwin()) PPCTarget = TargetDarwin; } } From lattner at cs.uiuc.edu Sat Aug 6 23:25:50 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Sat, 6 Aug 2005 23:25:50 -0500 Subject: [llvm-commits] CVS: llvm/test/Regression/Transforms/TailCallElim/dont-tce-tail-marked-call.ll move_alloca_for_tail_call.ll Message-ID: <200508070425.XAA29479@zion.cs.uiuc.edu> Changes in directory llvm/test/Regression/Transforms/TailCallElim: dont-tce-tail-marked-call.ll added (r1.1) move_alloca_for_tail_call.ll added (r1.1) --- Log message: New testcases for PR615: http://llvm.cs.uiuc.edu/PR615 --- Diffs of the changes: (+22 -0) dont-tce-tail-marked-call.ll | 11 +++++++++++ move_alloca_for_tail_call.ll | 11 +++++++++++ 2 files changed, 22 insertions(+) Index: llvm/test/Regression/Transforms/TailCallElim/dont-tce-tail-marked-call.ll diff -c /dev/null llvm/test/Regression/Transforms/TailCallElim/dont-tce-tail-marked-call.ll:1.1 *** /dev/null Sat Aug 6 23:25:49 2005 --- llvm/test/Regression/Transforms/TailCallElim/dont-tce-tail-marked-call.ll Sat Aug 6 23:25:39 2005 *************** *** 0 **** --- 1,11 ---- + ; RUN: llvm-as < %s | opt -tailcallelim | llvm-dis | grep 'call int %foo' + + declare void %bar(int*) + int %foo(uint %N) { + %A = alloca int, uint %N ;; Should stay in entry block because of 'tail' marker + store int 17, int* %A + call void %bar(int* %A) + + %X = tail call int %foo(uint %N) ;; Cannot -tailcallelim this without increasing stack usage! + ret int %X + } Index: llvm/test/Regression/Transforms/TailCallElim/move_alloca_for_tail_call.ll diff -c /dev/null llvm/test/Regression/Transforms/TailCallElim/move_alloca_for_tail_call.ll:1.1 *** /dev/null Sat Aug 6 23:25:50 2005 --- llvm/test/Regression/Transforms/TailCallElim/move_alloca_for_tail_call.ll Sat Aug 6 23:25:39 2005 *************** *** 0 **** --- 1,11 ---- + ; RUN: llvm-as < %s | opt -tailcallelim | llvm-dis | %prcontext alloca 1 | grep 'int %foo' + + declare void %bar(int*) + int %foo() { + %A = alloca int ;; Should stay in entry block because of 'tail' marker + store int 17, int* %A + call void %bar(int* %A) + + %X = tail call int %foo() + ret int %X + } From lattner at cs.uiuc.edu Sat Aug 6 23:27:52 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Sat, 6 Aug 2005 23:27:52 -0500 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp Message-ID: <200508070427.XAA29497@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Scalar: TailRecursionElimination.cpp updated: 1.18 -> 1.19 --- Log message: * Use the new PHINode::hasConstantValue method to simplify some code * Teach this code to move allocas out of the loop when tail call eliminating a call marked 'tail'. This implements TailCallElim/move_alloca_for_tail_call.ll * Do not perform this transformation if a call is marked 'tail' and if there are allocas that we cannot move out of the loop in #2. Doing so would increase the stack usage of the function. This implements fixes PR615: http://llvm.cs.uiuc.edu/PR615 and TailCallElim/dont-tce-tail-marked-call.ll. --- Diffs of the changes: (+66 -26) TailRecursionElimination.cpp | 92 ++++++++++++++++++++++++++++++------------- 1 files changed, 66 insertions(+), 26 deletions(-) Index: llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp diff -u llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp:1.18 llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp:1.19 --- llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp:1.18 Wed Jul 27 01:12:34 2005 +++ llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp Sat Aug 6 23:27:41 2005 @@ -51,6 +51,7 @@ //===----------------------------------------------------------------------===// #include "llvm/Transforms/Scalar.h" +#include "llvm/Constants.h" #include "llvm/DerivedTypes.h" #include "llvm/Function.h" #include "llvm/Instructions.h" @@ -68,7 +69,9 @@ private: bool ProcessReturningBlock(ReturnInst *RI, BasicBlock *&OldEntry, - std::vector &ArgumentPHIs); + bool &TailCallsAreMarkedTail, + std::vector &ArgumentPHIs, + bool CannotTailCallElimCallsMarkedTail); bool CanMoveAboveCall(Instruction *I, CallInst *CI); Value *CanTransformAccumulatorRecursion(Instruction *I, CallInst *CI); }; @@ -93,12 +96,21 @@ /// FunctionContainsAllocas - Scan the specified basic block for alloca /// instructions. If it contains any that might be accessed by calls, return /// true. -static bool CheckForEscapingAllocas(BasicBlock *BB) { +static bool CheckForEscapingAllocas(BasicBlock *BB, + bool &CannotTCETailMarkedCall) { + bool RetVal = false; for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) - if (AllocaInst *AI = dyn_cast(I)) - if (AllocaMightEscapeToCalls(AI)) - return true; - return false; + if (AllocaInst *AI = dyn_cast(I)) { + RetVal |= AllocaMightEscapeToCalls(AI); + + // If this alloca is in the body of the function, or if it is a variable + // sized allocation, we cannot tail call eliminate calls marked 'tail' + // with this mechanism. + if (BB != &BB->getParent()->front() || + !isa(AI->getArraySize())) + CannotTCETailMarkedCall = true; + } + return RetVal; } bool TailCallElim::runOnFunction(Function &F) { @@ -107,21 +119,34 @@ if (F.getFunctionType()->isVarArg()) return false; BasicBlock *OldEntry = 0; + bool TailCallsAreMarkedTail = false; std::vector ArgumentPHIs; bool MadeChange = false; bool FunctionContainsEscapingAllocas = false; + // CannotTCETailMarkedCall - If true, we cannot perform TCE on tail calls + // marked with the 'tail' attribute, because doing so would cause the stack + // size to increase (real TCE would deallocate variable sized allocas, TCE + // doesn't). + bool CannotTCETailMarkedCall = false; + // Loop over the function, looking for any returning blocks, and keeping track // of whether this function has any non-trivially used allocas. for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) { - if (!FunctionContainsEscapingAllocas) - FunctionContainsEscapingAllocas = CheckForEscapingAllocas(BB); + if (FunctionContainsEscapingAllocas && CannotTCETailMarkedCall) + break; - if (ReturnInst *Ret = dyn_cast(BB->getTerminator())) - MadeChange |= ProcessReturningBlock(Ret, OldEntry, ArgumentPHIs); + FunctionContainsEscapingAllocas = + CheckForEscapingAllocas(BB, CannotTCETailMarkedCall); } + // Second pass, change any tail calls to loops. + for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) + if (ReturnInst *Ret = dyn_cast(BB->getTerminator())) + MadeChange |= ProcessReturningBlock(Ret, OldEntry, TailCallsAreMarkedTail, + ArgumentPHIs,CannotTCETailMarkedCall); + // If we eliminated any tail recursions, it's possible that we inserted some // silly PHI nodes which just merge an initial value (the incoming operand) // with themselves. Check to see if we did and clean up our mess if so. This @@ -131,23 +156,11 @@ unsigned NumIncoming = ArgumentPHIs[0]->getNumIncomingValues(); for (unsigned i = 0, e = ArgumentPHIs.size(); i != e; ++i) { PHINode *PN = ArgumentPHIs[i]; - Value *V = 0; - for (unsigned op = 0, e = NumIncoming; op != e; ++op) { - Value *Op = PN->getIncomingValue(op); - if (Op != PN) { - if (V == 0) { - V = Op; // First value seen? - } else if (V != Op) { - V = 0; - break; - } - } - } // If the PHI Node is a dynamic constant, replace it with the value it is. - if (V) { - PN->replaceAllUsesWith(V); - PN->getParent()->getInstList().erase(PN); + if (Value *PNV = PN->hasConstantValue()) { + PN->replaceAllUsesWith(PNV); + PN->eraseFromParent(); } } } @@ -268,7 +281,9 @@ } bool TailCallElim::ProcessReturningBlock(ReturnInst *Ret, BasicBlock *&OldEntry, - std::vector &ArgumentPHIs) { + bool &TailCallsAreMarkedTail, + std::vector &ArgumentPHIs, + bool CannotTailCallElimCallsMarkedTail) { BasicBlock *BB = Ret->getParent(); Function *F = BB->getParent(); @@ -289,6 +304,11 @@ --BBI; } + // If this call is marked as a tail call, and if there are dynamic allocas in + // the function, we cannot perform this optimization. + if (CI->isTailCall() && CannotTailCallElimCallsMarkedTail) + return false; + // If we are introducing accumulator recursion to eliminate associative // operations after the call instruction, this variable contains the initial // value for the accumulator. If this value is set, we actually perform @@ -334,6 +354,17 @@ BasicBlock *NewEntry = new BasicBlock(OldName, F, OldEntry); new BranchInst(OldEntry, NewEntry); + // If this tail call is marked 'tail' and if there are any allocas in the + // entry block, move them up to the new entry block. + TailCallsAreMarkedTail = CI->isTailCall(); + if (TailCallsAreMarkedTail) + // Move all fixed sized allocas from OldEntry to NewEntry. + for (BasicBlock::iterator OEBI = OldEntry->begin(), E = OldEntry->end(), + NEBI = NewEntry->begin(); OEBI != E; ) + if (AllocaInst *AI = dyn_cast(OEBI++)) + if (isa(AI->getArraySize())) + NewEntry->getInstList().splice(NEBI, OldEntry->getInstList(), AI); + // Now that we have created a new block, which jumps to the entry // block, insert a PHI node for each argument of the function. // For now, we initialize each PHI to only have the real arguments @@ -348,6 +379,15 @@ } } + // If this function has self recursive calls in the tail position where some + // are marked tail and some are not, only transform one flavor or another. We + // have to choose whether we move allocas in the entry block to the new entry + // block or not, so we can't make a good choice for both. NOTE: We could do + // slightly better here in the case that the function has no entry block + // allocas. + if (TailCallsAreMarkedTail && !CI->isTailCall()) + return false; + // Ok, now that we know we have a pseudo-entry block WITH all of the // required PHI nodes, add entries into the PHI node for the actual // parameters passed into the tail-recursive call. From lattner at cs.uiuc.edu Sun Aug 7 00:00:55 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Sun, 7 Aug 2005 00:00:55 -0500 Subject: [llvm-commits] CVS: llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp Message-ID: <200508070500.AAA03050@zion.cs.uiuc.edu> Changes in directory llvm/lib/CodeGen/SelectionDAG: SelectionDAG.cpp updated: 1.128 -> 1.129 --- Log message: add a small simplification that can be exposed after promotion/expansion --- Diffs of the changes: (+7 -2) SelectionDAG.cpp | 9 +++++++-- 1 files changed, 7 insertions(+), 2 deletions(-) Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp diff -u llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1.128 llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1.129 --- llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1.128 Fri Aug 5 11:55:31 2005 +++ llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp Sun Aug 7 00:00:44 2005 @@ -770,8 +770,6 @@ // If we know the result of a setcc has the top bits zero, use this info. switch (Op.getOpcode()) { - case ISD::UNDEF: - return true; case ISD::Constant: return (cast(Op)->getValue() & Mask) == 0; @@ -1044,6 +1042,13 @@ MVT::getSizeInBits(cast(N1.getOperand(1))->getVT()); if ((C2 & (~0ULL << ExtendBits)) == 0) return getNode(ISD::AND, VT, N1.getOperand(0), N2); + } else if (N1.getOpcode() == ISD::OR) { + if (ConstantSDNode *ORI = dyn_cast(N1.getOperand(1))) + if ((ORI->getValue() & C2) == C2) { + // If the 'or' is setting all of the bits that we are masking for, + // we know the result of the AND will be the AND mask itself. + return N2; + } } break; case ISD::OR: From lattner at cs.uiuc.edu Sun Aug 7 02:01:03 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Sun, 7 Aug 2005 02:01:03 -0500 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp Message-ID: <200508070701.CAA08011@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Scalar: TailRecursionElimination.cpp updated: 1.19 -> 1.20 --- Log message: Fix typoCVS: ---------------------------------------------------------------------- --- Diffs of the changes: (+1 -1) TailRecursionElimination.cpp | 2 +- 1 files changed, 1 insertion(+), 1 deletion(-) Index: llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp diff -u llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp:1.19 llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp:1.20 --- llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp:1.19 Sat Aug 6 23:27:41 2005 +++ llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp Sun Aug 7 02:00:52 2005 @@ -137,7 +137,7 @@ if (FunctionContainsEscapingAllocas && CannotTCETailMarkedCall) break; - FunctionContainsEscapingAllocas = + FunctionContainsEscapingAllocas |= CheckForEscapingAllocas(BB, CannotTCETailMarkedCall); } From lattner at cs.uiuc.edu Sun Aug 7 02:03:21 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Sun, 7 Aug 2005 02:03:21 -0500 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp Message-ID: <200508070703.CAA08541@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Scalar: InstructionCombining.cpp updated: 1.363 -> 1.364 --- Log message: Add some simple folds that occur in bitfield cases. Fix a minor bug in isHighOnes, where it would consider 0 to have high ones. --- Diffs of the changes: (+32 -0) InstructionCombining.cpp | 32 ++++++++++++++++++++++++++++++++ 1 files changed, 32 insertions(+) Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.363 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.364 --- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.363 Thu Aug 4 20:04:30 2005 +++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Sun Aug 7 02:03:10 2005 @@ -1215,6 +1215,7 @@ // This is the same as lowones(~X). static bool isHighOnes(const ConstantInt *CI) { uint64_t V = ~CI->getRawValue(); + if (~V == 0) return false; // 0's does not match "1+" // There won't be bits set in parts that the type doesn't contain. V &= ConstantInt::getAllOnesValue(CI->getType())->getRawValue(); @@ -1636,6 +1637,37 @@ } else if (CastInst *CI = dyn_cast(Op0)) { const Type *SrcTy = CI->getOperand(0)->getType(); + // If this is an integer truncation or change from signed-to-unsigned, and + // if the source is an and/or with immediate, transform it. This + // frequently occurs for bitfield accesses. + if (Instruction *CastOp = dyn_cast(CI->getOperand(0))) { + if (SrcTy->getPrimitiveSizeInBits() >= + I.getType()->getPrimitiveSizeInBits() && + CastOp->getNumOperands() == 2) + if (ConstantInt *AndCI =dyn_cast(CastOp->getOperand(1))) + if (CastOp->getOpcode() == Instruction::And) { + // Change: and (cast (and X, C1) to T), C2 + // into : and (cast X to T), trunc(C1)&C2 + // This will folds the two ands together, which may allow other + // simplifications. + Instruction *NewCast = + new CastInst(CastOp->getOperand(0), I.getType(), + CastOp->getName()+".shrunk"); + NewCast = InsertNewInstBefore(NewCast, I); + + Constant *C3=ConstantExpr::getCast(AndCI, I.getType());//trunc(C1) + C3 = ConstantExpr::getAnd(C3, AndRHS); // trunc(C1)&C2 + return BinaryOperator::createAnd(NewCast, C3); + } else if (CastOp->getOpcode() == Instruction::Or) { + // Change: and (cast (or X, C1) to T), C2 + // into : trunc(C1)&C2 iff trunc(C1)&C2 == C2 + Constant *C3=ConstantExpr::getCast(AndCI, I.getType());//trunc(C1) + if (ConstantExpr::getAnd(C3, AndRHS) == AndRHS) // trunc(C1)&C2 + return ReplaceInstUsesWith(I, AndRHS); + } + } + + // If this is an integer sign or zero extension instruction. if (SrcTy->isIntegral() && SrcTy->getPrimitiveSizeInBits() < From lattner at cs.uiuc.edu Sun Aug 7 15:02:15 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Sun, 7 Aug 2005 15:02:15 -0500 Subject: [llvm-commits] CVS: llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp Message-ID: <200508072002.PAA23769@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/IPO: SimplifyLibCalls.cpp updated: 1.47 -> 1.48 --- Log message: All stats are "Number of ..." --- Diffs of the changes: (+1 -1) SimplifyLibCalls.cpp | 2 +- 1 files changed, 1 insertion(+), 1 deletion(-) Index: llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp diff -u llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp:1.47 llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp:1.48 --- llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp:1.47 Mon Aug 1 11:52:50 2005 +++ llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp Sun Aug 7 15:02:04 2005 @@ -36,7 +36,7 @@ /// This statistic keeps track of the total number of library calls that have /// been simplified regardless of which call it is. Statistic<> SimplifiedLibCalls("simplify-libcalls", - "Total number of library calls simplified"); + "Number of library calls simplified"); // Forward declarations class LibCallOptimization; From alenhar2 at cs.uiuc.edu Sun Aug 7 18:26:28 2005 From: alenhar2 at cs.uiuc.edu (Andrew Lenharth) Date: Sun, 7 Aug 2005 18:26:28 -0500 Subject: [llvm-commits] CVS: llvm-test/Makefile.programs Message-ID: <200508072326.SAA30895@zion.cs.uiuc.edu> Changes in directory llvm-test: Makefile.programs updated: 1.160 -> 1.161 --- Log message: get the FTOI opt right --- Diffs of the changes: (+1 -1) Makefile.programs | 2 +- 1 files changed, 1 insertion(+), 1 deletion(-) Index: llvm-test/Makefile.programs diff -u llvm-test/Makefile.programs:1.160 llvm-test/Makefile.programs:1.161 --- llvm-test/Makefile.programs:1.160 Fri Aug 5 16:24:11 2005 +++ llvm-test/Makefile.programs Sun Aug 7 18:26:17 2005 @@ -191,7 +191,7 @@ #-enable-gpopt endif ifeq ($(ARCH),Alpha) -LLCBETAOPTION := -enable-alpha-ftoi -enable-lsr-for-alpha +LLCBETAOPTION := -enable-alpha-FTOI -enable-lsr-for-alpha #-enable-alpha-intfpdiv endif ifeq ($(ARCH),x86) From lattner at cs.uiuc.edu Sun Aug 7 23:26:43 2005 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Sun, 7 Aug 2005 23:26:43 -0500 Subject: [llvm-commits] CVS: llvm/lib/CodeGen/AsmPrinter.cpp Message-ID: <200508080426.XAA01029@zion.cs.uiuc.edu> Changes in directory llvm/lib/CodeGen: AsmPrinter.cpp updated: 1.18 -> 1.19 --- Log message: Handle 64-bit constant exprs on 64-bit targets. --- Diffs of the changes: (+3 -1) AsmPrinter.cpp | 4 +++- 1 files changed, 3 insertions(+), 1 deletion(-) Index: llvm/lib/CodeGen/AsmPrinter.cpp diff -u llvm/lib/CodeGen/AsmPrinter.cpp:1.18 llvm/lib/CodeGen/AsmPrinter.cpp:1.19 --- llvm/lib/CodeGen/AsmPrinter.cpp:1.18 Sun May 15 08:05:48 2005 +++ llvm/lib/CodeGen/AsmPrinter.cpp Sun Aug 7 23:26:32 2005 @@ -302,7 +302,9 @@ O << Data32bitsDirective; break; case Type::ULongTyID: case Type::LongTyID: - assert (0 && "Should have already output double-word constant."); + assert(Data64bitsDirective &&"Target cannot handle 64-bit constant exprs!"); + O << Data64bitsDirective; + break; case Type::FloatTyID: case Type::DoubleTyID: assert (0 && "Should have already output floating point constant."); default: