forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ashton Wiersdorf: optimize that the range of x*x is positive for floa…
…ts (llvm#44) * First draft of optimization for x^2 + c₁ >= c₂ Optimize x^2 + c₁ >= c₂ → True whenever c₁ >= c₂ * WIP refactoring * Update logic Still not working—seems to be a wraparound issue * Convert optimization to floating point; seems to work * Fix bug; add test * Wrap optimization in {} to keep variables scoped easily * Fix whitespace change
- Loading branch information
Showing
2 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
; RUN: opt < %s -passes=instcombine -S | FileCheck %s | ||
|
||
; positive tests | ||
; x * x + c1 > c2 where c1 > c2 => isnan(x) | ||
define i32 @t1(float %x) { | ||
%1 = fmul float %x, %x | ||
%2 = fadd float %1, 77.0e+00 | ||
%3 = fcmp ogt float %2, 22.0e+00 | ||
%4 = select i1 %3, i32 1, i32 2 | ||
ret i32 %4 | ||
; CHECK-LABEL: @t1( | ||
; CHECK: [[r1:%.*]] = fcmp ord float %x, 0.000000e+00 | ||
; CHECK-NEXT: [[r2:%.*]] = select i1 [[r1]], i32 1, i32 2 | ||
; CHECK-NEXT: ret i32 [[r2]] | ||
} | ||
|
||
; x * x + c1 < c2 where c1 > c2 => false | ||
define i32 @t2(float %x) { | ||
%1 = fmul float %x, %x | ||
%2 = fadd float %1, 77.0e+00 | ||
%3 = fcmp olt float %2, 22.0e+00 | ||
%4 = select i1 %3, i32 1, i32 2 | ||
ret i32 %4 | ||
; CHECK-LABEL: @t2( | ||
; CHECK-NEXT: ret i32 2 | ||
} | ||
|
||
; negative test | ||
; x * x + c1 > c2 where c1 < c2 => no optimization | ||
define i32 @t3(float %x) { | ||
%1 = fmul float %x, %x | ||
%2 = fadd float %1, 22.0e+00 | ||
%3 = fcmp ogt float %2, 77.0e+00 | ||
%4 = select i1 %3, i32 1, i32 2 | ||
ret i32 %4 | ||
; CHECK-LABEL: @t3( | ||
; CHECK-NOT: [[r0:%.*]] = fcmp ord float %x, 0.000000e+00 | ||
; CHECK: [[r1:%.*]] = fcmp ogt float %2, 7.700000e+01 | ||
; CHECK-NEXT: [[r2:%.*]] = select i1 [[r1]], i32 1, i32 2 | ||
; CHECK-NEXT: ret i32 [[r2]] | ||
} |