[llvm] r240212 - Revert r240040, "[BranchFolding] Replace custom MachineInstr with MachineInstrExpressionTrait"

Benjamin Kramer benny.kra at gmail.com
Sat Jun 20 04:26:51 PDT 2015


> On 20.06.2015, at 08:21, NAKAMURA Takumi <geek4civic at gmail.com> wrote:
> 
> Author: chapuni
> Date: Sat Jun 20 01:21:48 2015
> New Revision: 240212
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=240212&view=rev
> Log:
> Revert r240040, "[BranchFolding] Replace custom MachineInstr with MachineInstrExpressionTrait"
> 
> It caused different emission between stage2 and stage3. Investigating.

Looks like it's mixing pointers into the hash and then sorting the table by hash. Yep, that's nondeterministic :(

- Ben 

> 
> Modified:
>    llvm/trunk/lib/CodeGen/BranchFolding.cpp
> 
> Modified: llvm/trunk/lib/CodeGen/BranchFolding.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/BranchFolding.cpp?rev=240212&r1=240211&r2=240212&view=diff
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/BranchFolding.cpp (original)
> +++ llvm/trunk/lib/CodeGen/BranchFolding.cpp Sat Jun 20 01:21:48 2015
> @@ -264,14 +264,54 @@ bool BranchFolder::OptimizeFunction(Mach
> //  Tail Merging of Blocks
> //===----------------------------------------------------------------------===//
> 
> +/// HashMachineInstr - Compute a hash value for MI and its operands.
> +static unsigned HashMachineInstr(const MachineInstr *MI) {
> +  unsigned Hash = MI->getOpcode();
> +  for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
> +    const MachineOperand &Op = MI->getOperand(i);
> +
> +    // Merge in bits from the operand if easy.
> +    unsigned OperandHash = 0;
> +    switch (Op.getType()) {
> +    case MachineOperand::MO_Register:          OperandHash = Op.getReg(); break;
> +    case MachineOperand::MO_Immediate:         OperandHash = Op.getImm(); break;
> +    case MachineOperand::MO_MachineBasicBlock:
> +      OperandHash = Op.getMBB()->getNumber();
> +      break;
> +    case MachineOperand::MO_FrameIndex:
> +    case MachineOperand::MO_ConstantPoolIndex:
> +    case MachineOperand::MO_JumpTableIndex:
> +      OperandHash = Op.getIndex();
> +      break;
> +    case MachineOperand::MO_GlobalAddress:
> +    case MachineOperand::MO_ExternalSymbol:
> +      // Global address / external symbol are too hard, don't bother, but do
> +      // pull in the offset.
> +      OperandHash = Op.getOffset();
> +      break;
> +    default: break;
> +    }
> +
> +    Hash += ((OperandHash << 3) | Op.getType()) << (i&31);
> +  }
> +  return Hash;
> +}
> +
> /// HashEndOfMBB - Hash the last instruction in the MBB.
> static unsigned HashEndOfMBB(const MachineBasicBlock *MBB) {
> -  auto LastInst = MBB->getLastNonDebugInstr();
> -  if (LastInst == MBB->end())
> -    return 0;
> -  // Hash the instruction and all operands. MachineInstrExpressionTrait ignores
> -  // vreg defs when computing the hash but we're post-regalloc here.
> -  return MachineInstrExpressionTrait::getHashValue(LastInst);
> +  MachineBasicBlock::const_iterator I = MBB->end();
> +  if (I == MBB->begin())
> +    return 0;   // Empty MBB.
> +
> +  --I;
> +  // Skip debug info so it will not affect codegen.
> +  while (I->isDebugValue()) {
> +    if (I==MBB->begin())
> +      return 0;      // MBB empty except for debug info.
> +    --I;
> +  }
> +
> +  return HashMachineInstr(I);
> }
> 
> /// ComputeCommonTailLength - Given two machine basic blocks, compute the number
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits





More information about the llvm-commits mailing list