Skip to content

Commit 01e19e8

Browse files
authored
[InstCombine] Mark as unknown the branch weights of packed integer selecting shifts (#162726)
Follow up from PR #162147. We do not have existing !prof metadata to synthesize one for the new `select`​ . Fixes https://lab.llvm.org/staging/#/builders/221/builds/3091 Issue #147390
1 parent 01c7ef6 commit 01e19e8

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

llvm/lib/Transforms/InstCombine/InstCombineInternal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ class LLVM_LIBRARY_VISIBILITY InstCombinerImpl final
471471
Value *simplifyNonNullOperand(Value *V, bool HasDereferenceable,
472472
unsigned Depth = 0);
473473

474+
public:
474475
/// Create `select C, S1, S2`. Use only when the profile cannot be calculated
475476
/// from existing profile metadata: if the Function has profiles, this will
476477
/// set the profile of this select to "unknown".
@@ -483,7 +484,6 @@ class LLVM_LIBRARY_VISIBILITY InstCombinerImpl final
483484
return Sel;
484485
}
485486

486-
public:
487487
/// Create and insert the idiom we use to indicate a block is unreachable
488488
/// without having to rewrite the CFG from within InstCombine.
489489
void CreateNonTerminatorUnreachable(Instruction *InsertAt) {

llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "llvm/IR/GetElementPtrTypeIterator.h"
1717
#include "llvm/IR/IntrinsicInst.h"
1818
#include "llvm/IR/PatternMatch.h"
19+
#include "llvm/IR/ProfDataUtils.h"
1920
#include "llvm/Support/KnownBits.h"
2021
#include "llvm/Transforms/InstCombine/InstCombiner.h"
2122

@@ -107,7 +108,10 @@ static Value *simplifyShiftSelectingPackedElement(Instruction *I,
107108
Value *ShrAmtZ =
108109
IC.Builder.CreateICmpEQ(ShrAmt, Constant::getNullValue(ShrAmt->getType()),
109110
ShrAmt->getName() + ".z");
110-
Value *Select = IC.Builder.CreateSelect(ShrAmtZ, Lower, Upper);
111+
// There is no existing !prof metadata we can derive the !prof metadata for
112+
// this select.
113+
Value *Select = IC.createSelectInstWithUnknownProfile(ShrAmtZ, Lower, Upper);
114+
IC.Builder.Insert(Select);
111115
Select->takeName(I);
112116
return Select;
113117
}

0 commit comments

Comments
 (0)