Skip to content

PR for llvm/llvm-project#58046 #174

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 2 commits into from
Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 11 additions & 2 deletions llvm/lib/Analysis/ValueTracking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3593,14 +3593,23 @@ static bool cannotBeOrderedLessThanZeroImpl(const Value *V,
// Unsigned integers are always nonnegative.
case Instruction::UIToFP:
return true;
case Instruction::FMul:
case Instruction::FDiv:
// X * X is always non-negative or a NaN.
// X / X is always exactly 1.0 or a NaN.
if (I->getOperand(0) == I->getOperand(1) &&
(!SignBitOnly || cast<FPMathOperator>(I)->hasNoNaNs()))
return true;

// Set SignBitOnly for RHS, because X / -0.0 is -Inf (or NaN).
return cannotBeOrderedLessThanZeroImpl(I->getOperand(0), TLI, SignBitOnly,
Depth + 1) &&
cannotBeOrderedLessThanZeroImpl(I->getOperand(1), TLI,
/*SignBitOnly*/ true, Depth + 1);
case Instruction::FMul:
// X * X is always non-negative or a NaN.
if (I->getOperand(0) == I->getOperand(1) &&
(!SignBitOnly || cast<FPMathOperator>(I)->hasNoNaNs()))
return true;

LLVM_FALLTHROUGH;
case Instruction::FAdd:
case Instruction::FRem:
Expand Down
16 changes: 16 additions & 0 deletions llvm/test/Transforms/InstSimplify/floating-point-compare.ll
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,22 @@ define <2 x i1> @known_positive_une_with_negative_constant_splat_vec(<2 x i32> %
ret <2 x i1> %cmp
}

; TODO: This could fold to true.
define i1 @pr58046(i64 %arg) {
; CHECK-LABEL: @pr58046(
; CHECK-NEXT: [[FP:%.*]] = uitofp i64 [[ARG:%.*]] to double
; CHECK-NEXT: [[MUL:%.*]] = fmul double -0.000000e+00, [[FP]]
; CHECK-NEXT: [[DIV:%.*]] = fdiv double 1.000000e+00, [[MUL]]
; CHECK-NEXT: [[CMP:%.*]] = fcmp oeq double [[DIV]], 0xFFF0000000000000
; CHECK-NEXT: ret i1 [[CMP]]
;
%fp = uitofp i64 %arg to double
%mul = fmul double -0.000000e+00, %fp
%div = fdiv double 1.000000e+00, %mul
%cmp = fcmp oeq double %div, 0xFFF0000000000000
ret i1 %cmp
}

define i1 @nonans1(double %in1, double %in2) {
; CHECK-LABEL: @nonans1(
; CHECK-NEXT: ret i1 false
Expand Down