Skip to content

[ValueTracking] Fix assertion failure when computeKnownFPClass returns fcNone #92355

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

Merged
merged 3 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions llvm/lib/Analysis/ValueTracking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1126,8 +1126,13 @@ static void computeKnownBitsFromOperator(const Operator *I,
KnownFPClass Result = computeKnownFPClass(V, fcAllFlags, Depth + 1, Q);
FPClassTest FPClasses = Result.KnownFPClasses;

if (FPClasses != fcNone &&
Result.isKnownNever(fcNormal | fcSubnormal | fcNan)) {
// Treat it as zero if the use of I is unreachable.
if (FPClasses == fcNone) {
Known.setAllZero();
break;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably should do this as a separate PR, this probably has the need-to-consistently-be-zero-for-undef problem

Copy link
Member Author

Choose a reason for hiding this comment

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

I will leave it as a todo.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's probably OK as long as we handle undef correctly inside computeKnownFPClass, the contradictory paths implies UB happened somewhere


if (Result.isKnownNever(fcNormal | fcSubnormal | fcNan)) {
Known.Zero.setAllBits();
Known.One.setAllBits();

Expand Down
8 changes: 2 additions & 6 deletions llvm/test/Transforms/InstCombine/known-bits.ll
Original file line number Diff line number Diff line change
Expand Up @@ -1666,9 +1666,7 @@ define i64 @pr92084(double %x) {
; CHECK: if.then1:
; CHECK-NEXT: br i1 [[CMP]], label [[IF_ELSE]], label [[IF_THEN2:%.*]]
; CHECK: if.then2:
; CHECK-NEXT: [[CAST:%.*]] = bitcast double [[X]] to i64
; CHECK-NEXT: [[AND:%.*]] = and i64 [[CAST]], 1
; CHECK-NEXT: ret i64 [[AND]]
; CHECK-NEXT: ret i64 0
; CHECK: if.else:
; CHECK-NEXT: ret i64 0
;
Expand All @@ -1689,9 +1687,7 @@ if.else:

define i32 @test_none(float nofpclass(all) %x) {
; CHECK-LABEL: @test_none(
; CHECK-NEXT: [[Y:%.*]] = bitcast float [[X:%.*]] to i32
; CHECK-NEXT: [[AND:%.*]] = and i32 [[Y]], 4194304
; CHECK-NEXT: ret i32 [[AND]]
; CHECK-NEXT: ret i32 0
;
%y = bitcast float %x to i32
%and = and i32 %y, 4194304
Expand Down