Skip to content

Commit a94ee7e

Browse files
[InstCombine] Fix profile metadata when folding implied conditionals (#170756)
\#163412 touched this last and directly propagated the profile information. This was not correct for the motivating example: %a = icmp eq i32 %z, 0 %b = icmp eq i32 %z, 1 %v2 = select i1 %b, i1 true, i1 %pred, !prof !18 %v3 = and i1 %a, %v2 to %a = icmp eq i32 %z, 0 %v3 = select i1 %a, i1 %pred, i1 false z == 1 does not imply that z == 0 for i8. In general for the and case, we need a => b, which means that b must be equivalent or more restrictive than a, which means we cannot propagate profile information without additional information on the value distribution of z. For the or case we need !a => b. We again cannot derive profile information for a/!a without additional value distribution information.
1 parent f71be40 commit a94ee7e

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3067,14 +3067,10 @@ Instruction *InstCombinerImpl::foldAndOrOfSelectUsingImpliedCond(Value *Op,
30673067
"Op must be either i1 or vector of i1.");
30683068
if (SI.getCondition()->getType() != Op->getType())
30693069
return nullptr;
3070-
if (Value *V = simplifyNestedSelectsUsingImpliedCond(SI, Op, IsAnd, DL)) {
3071-
Instruction *MDFrom = nullptr;
3072-
if (!ProfcheckDisableMetadataFixes)
3073-
MDFrom = &SI;
3074-
return SelectInst::Create(
3070+
if (Value *V = simplifyNestedSelectsUsingImpliedCond(SI, Op, IsAnd, DL))
3071+
return createSelectInstWithUnknownProfile(
30753072
Op, IsAnd ? V : ConstantInt::getTrue(Op->getType()),
3076-
IsAnd ? ConstantInt::getFalse(Op->getType()) : V, "", nullptr, MDFrom);
3077-
}
3073+
IsAnd ? ConstantInt::getFalse(Op->getType()) : V);
30783074
return nullptr;
30793075
}
30803076

llvm/test/Transforms/InstCombine/select-safe-impliedcond-transforms.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,5 +263,5 @@ define i1 @neg_icmp_eq_implies_trunc(i8 %x, i1 %c) {
263263
!1 = !{!"branch_weights", i32 2, i32 3}
264264
;.
265265
; CHECK: [[META0:![0-9]+]] = !{!"function_entry_count", i64 1000}
266-
; CHECK: [[PROF1]] = !{!"branch_weights", i32 2, i32 3}
266+
; CHECK: [[PROF1]] = !{!"unknown", !"instcombine"}
267267
;.

0 commit comments

Comments
 (0)