-
Notifications
You must be signed in to change notification settings - Fork 15.5k
[InstCombine] Fix profile metadata when folding implied conditionals #170756
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[InstCombine] Fix profile metadata when folding implied conditionals #170756
Conversation
\llvm#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.
|
@llvm/pr-subscribers-llvm-transforms Author: Aiden Grossman (boomanaiden154) Changes#163412 touched this last and directly propagated the profile information. This was not correct for the motivating example: %a = icmp eq i32 %z, 0 to %a = icmp eq i32 %z, 0 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. Full diff: https://github.com/llvm/llvm-project/pull/170756.diff 2 Files Affected:
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
index c9f51e4b294b1..c00551bc1f939 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
@@ -3067,14 +3067,10 @@ Instruction *InstCombinerImpl::foldAndOrOfSelectUsingImpliedCond(Value *Op,
"Op must be either i1 or vector of i1.");
if (SI.getCondition()->getType() != Op->getType())
return nullptr;
- if (Value *V = simplifyNestedSelectsUsingImpliedCond(SI, Op, IsAnd, DL)) {
- Instruction *MDFrom = nullptr;
- if (!ProfcheckDisableMetadataFixes)
- MDFrom = &SI;
- return SelectInst::Create(
+ if (Value *V = simplifyNestedSelectsUsingImpliedCond(SI, Op, IsAnd, DL))
+ return createSelectInstWithUnknownProfile(
Op, IsAnd ? V : ConstantInt::getTrue(Op->getType()),
- IsAnd ? ConstantInt::getFalse(Op->getType()) : V, "", nullptr, MDFrom);
- }
+ IsAnd ? ConstantInt::getFalse(Op->getType()) : V);
return nullptr;
}
diff --git a/llvm/test/Transforms/InstCombine/select-safe-impliedcond-transforms.ll b/llvm/test/Transforms/InstCombine/select-safe-impliedcond-transforms.ll
index bc988a9bbab04..d783cbf25de28 100644
--- a/llvm/test/Transforms/InstCombine/select-safe-impliedcond-transforms.ll
+++ b/llvm/test/Transforms/InstCombine/select-safe-impliedcond-transforms.ll
@@ -263,5 +263,5 @@ define i1 @neg_icmp_eq_implies_trunc(i8 %x, i1 %c) {
!1 = !{!"branch_weights", i32 2, i32 3}
;.
; CHECK: [[META0:![0-9]+]] = !{!"function_entry_count", i64 1000}
-; CHECK: [[PROF1]] = !{!"branch_weights", i32 2, i32 3}
+; CHECK: [[PROF1]] = !{!"unknown", !"instcombine"}
;.
|
nikic
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…lvm#170756) \llvm#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.
#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.