diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp index 0309e225d9df4..2dbf013fb40b8 100644 --- a/llvm/lib/CodeGen/CodeGenPrepare.cpp +++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp @@ -275,6 +275,9 @@ static cl::opt DisableDeletePHIs("disable-cgp-delete-phis", cl::Hidden, cl::init(false), cl::desc("Disable elimination of dead PHI nodes.")); +namespace llvm { +extern cl::opt ProfcheckDisableMetadataFixes; +} namespace { enum ExtType { @@ -7450,7 +7453,12 @@ bool CodeGenPrepare::optimizeShiftInst(BinaryOperator *Shift) { BinaryOperator::BinaryOps Opcode = Shift->getOpcode(); Value *NewTVal = Builder.CreateBinOp(Opcode, Shift->getOperand(0), TVal); Value *NewFVal = Builder.CreateBinOp(Opcode, Shift->getOperand(0), FVal); - Value *NewSel = Builder.CreateSelect(Cond, NewTVal, NewFVal); + Value *NewSel = + Builder.CreateSelect(Cond, NewTVal, NewFVal, /*Name=*/"", + /*MDFrom=*/ + ProfcheckDisableMetadataFixes + ? nullptr + : dyn_cast(Shift->getOperand(1))); replaceAllUsesWith(Shift, NewSel, FreshBBs, IsHugeFunc); Shift->eraseFromParent(); return true; @@ -7485,7 +7493,12 @@ bool CodeGenPrepare::optimizeFunnelShift(IntrinsicInst *Fsh) { Value *X = Fsh->getOperand(0), *Y = Fsh->getOperand(1); Value *NewTVal = Builder.CreateIntrinsic(Opcode, Ty, {X, Y, TVal}); Value *NewFVal = Builder.CreateIntrinsic(Opcode, Ty, {X, Y, FVal}); - Value *NewSel = Builder.CreateSelect(Cond, NewTVal, NewFVal); + Value *NewSel = + Builder.CreateSelect(Cond, NewTVal, NewFVal, /*Name=*/"", + /*MDFrom=*/ + ProfcheckDisableMetadataFixes + ? nullptr + : dyn_cast(Fsh->getOperand(2))); replaceAllUsesWith(Fsh, NewSel, FreshBBs, IsHugeFunc); Fsh->eraseFromParent(); return true;