-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean up treatment of fast-math flags during parsing
Currently, `llvm-pretty-bc-parser` skips over fast-math flags when parsing. However, it was doing so incorrectly when parsing `FUNC_CODE_INST_CMP2` (i.e., `fcmp` instructions). Per the LLVM source code [here](https://github.com/llvm/llvm-project/blob/b0391dfc737ede147e128fe877045f61fc5e4905/llvm/lib/Bitcode/Reader/BitcodeReader.cpp#L4342-L4377), the fast-math flags are expected to come after all of the other fields, but the code in `llvm-pretty-bc-parser` was assuming that they would appear in the middle. See #158. I addresses this issue by parsing all of the other fields upfront and avoiding parsing the last part, which correspond to fast-math flags. While I was in town, I also made sure to add comments in every other place in the parser where we avoid parsing fast-math flags.
- Loading branch information
1 parent
d1a6057
commit 544121a
Showing
2 changed files
with
49 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
; ModuleID = 'test.c' | ||
source_filename = "test.c" | ||
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" | ||
target triple = "x86_64-pc-linux-gnu" | ||
|
||
; Function Attrs: norecurse nounwind readnone uwtable | ||
define dso_local double @f(double %a) local_unnamed_addr #0 { | ||
entry: | ||
%tobool = fcmp fast une double %a, 0.000000e+00 | ||
%inc = fadd fast double %a, 1.000000e+00 | ||
%a.addr.0 = select i1 %tobool, double %inc, double %a | ||
ret double %a.addr.0 | ||
} | ||
|
||
attributes #0 = { norecurse nounwind readnone uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="true" "no-jump-tables"="false" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="true" "use-soft-float"="false" } | ||
|
||
!llvm.module.flags = !{!0} | ||
!llvm.ident = !{!1} | ||
!llvm.commandline = !{!2} | ||
|
||
!0 = !{i32 1, !"wchar_size", i32 4} | ||
!1 = !{!"clang version 10.0.0-4ubuntu1 "} | ||
!2 = !{!"/usr/lib/llvm-10/bin/clang -O3 test.c -emit-llvm -S -fno-discard-value-names -frecord-command-line -ffast-math"} |
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