aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis
diff options
context:
space:
mode:
authorBjörn Pettersson <bjorn.a.pettersson@ericsson.com>2024-03-07 21:32:49 +0100
committerGitHub <noreply@github.com>2024-03-07 21:32:49 +0100
commita41226b05510a6f40d99fc622d78853460dc5599 (patch)
tree5c426fd9b65821a9fb07af4cd1fc552f6e01078c /llvm/lib/Analysis
parentd0b702279819fe2fd3b3d2bfa274c895ac49f23b (diff)
downloadllvm-a41226b05510a6f40d99fc622d78853460dc5599.zip
llvm-a41226b05510a6f40d99fc622d78853460dc5599.tar.gz
llvm-a41226b05510a6f40d99fc622d78853460dc5599.tar.bz2
[ValueTracking] Fix KnownBits conflict for calls (range vs returned) (#84353)
If a function only exits for certain input values we can still derive that an argument is "returned". We can also derive range metadata that describe the possible value range returned by the function. However, it turns out that those two analyses can result in conflicting information. Example: declare i16 @foo(i16 returned) ... %A = call i16 @foo(i16 4095), !range !{i16 32, i16 33} To avoid "Bits known to be one AND zero?" assertion failures we know make sure to discard the known bits for this kind of scenario.
Diffstat (limited to 'llvm/lib/Analysis')
-rw-r--r--llvm/lib/Analysis/ValueTracking.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 52ae9f0..6d0e79e 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -1476,6 +1476,12 @@ static void computeKnownBitsFromOperator(const Operator *I,
if (RV->getType() == I->getType()) {
computeKnownBits(RV, Known2, Depth + 1, Q);
Known = Known.unionWith(Known2);
+ // If the function doesn't return properly for all input values
+ // (e.g. unreachable exits) then there might be conflicts between the
+ // argument value and the range metadata. Simply discard the known bits
+ // in case of conflicts.
+ if (Known.hasConflict())
+ Known.resetAll();
}
}
if (const IntrinsicInst *II = dyn_cast<IntrinsicInst>(I)) {