Skip to content

Conversation

@hassnaaHamdi
Copy link
Member

No description provided.

@hassnaaHamdi hassnaaHamdi requested a review from nikic as a code owner May 14, 2025 03:59
@llvmbot llvmbot added the llvm:analysis Includes value tracking, cost tables and constant folding label May 14, 2025
@llvmbot
Copy link
Member

llvmbot commented May 14, 2025

@llvm/pr-subscribers-llvm-analysis

Author: Hassnaa Hamdi (hassnaaHamdi)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/139832.diff

2 Files Affected:

  • (modified) llvm/include/llvm/Analysis/SimplifyQuery.h (+2)
  • (modified) llvm/lib/Analysis/ValueTracking.cpp (+4)
diff --git a/llvm/include/llvm/Analysis/SimplifyQuery.h b/llvm/include/llvm/Analysis/SimplifyQuery.h
index e8f43c8c2e91f..063ca4eaa9db0 100644
--- a/llvm/include/llvm/Analysis/SimplifyQuery.h
+++ b/llvm/include/llvm/Analysis/SimplifyQuery.h
@@ -62,6 +62,8 @@ struct InstrInfoQuery {
 struct CondContext {
   Value *Cond;
   bool Invert = false;
+  // Condition is true if CxtI is in the true successor of Cond.
+  bool CondIsTrue = false;
   SmallPtrSet<Value *, 4> AffectedValues;
 
   CondContext(Value *Cond) : Cond(Cond) {}
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 3d403531cea2f..527e8c549c04f 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -5014,6 +5014,10 @@ static KnownFPClass computeKnownFPClassFromContext(const Value *V,
                                                    const SimplifyQuery &Q) {
   KnownFPClass KnownFromContext;
 
+  if (Q.CC && Q.CC->AffectedValues.contains(V))
+    computeKnownFPClassFromCond(V, Q.CC->Cond, 0, Q.CC->CondIsTrue,
+                                Q.CxtI, KnownFromContext);
+
   if (!Q.CxtI)
     return KnownFromContext;
 

@github-actions
Copy link

github-actions bot commented May 14, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@hassnaaHamdi
Copy link
Member Author

Hi @nikic
This patch is a response to your comments here: #119677

Value *Cond;
bool Invert = false;
// Condition is true if CxtI is in the true successor of Cond.
bool CondIsTrue = false;
Copy link
Contributor

@nikic nikic May 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what Invert is for. (Or rather !Invert in this context.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
computeKnownFPClassFromCond(V, Q.CC->Cond, 0, Q.CC->Invert, Q.CxtI,
computeKnownFPClassFromCond(V, Q.CC->Cond, 0, !Q.CC->Invert, Q.CxtI,

This accepts CondIsTrue, so we should pass true for Invert=false.

Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@hassnaaHamdi hassnaaHamdi merged commit 67c67cd into llvm:main Jun 2, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

llvm:analysis Includes value tracking, cost tables and constant folding

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants