1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 19:12:56 +02:00

[SimplifyCFG] propagate fast-math-flags (FMF) from phi to select

Similar to/extension of D70208 (rGee0882bdf866), but this one
may finally allow closing motivating bugs.

This is another step towards having FMF apply only to FP values
rather than those + fcmp. See PR38086 for one of the original
discussions/motivations:
https://bugs.llvm.org/show_bug.cgi?id=38086

And the test here is derived from PR39535:
https://bugs.llvm.org/show_bug.cgi?id=39535

Currently, we lose FMF when converting any phi to select in
SimplifyCFG. There are a small number of similar changes needed
to correct within SimplifyCFG, so it should be quick to patch
this pass up.

FMF was extended to select and phi with:
D61917
D67564
This commit is contained in:
Sanjay Patel 2019-11-17 11:23:44 -05:00
parent 787ded74e9
commit d9f1077d04
2 changed files with 13 additions and 8 deletions

View File

@ -2425,7 +2425,12 @@ static bool FoldTwoEntryPHINode(PHINode *PN, const TargetTransformInfo &TTI,
if (IfBlock2)
hoistAllInstructionsInto(DomBlock, InsertPt, IfBlock2);
// Propagate fast-math-flags from phi nodes to replacement selects.
IRBuilder<>::FastMathFlagGuard FMFGuard(Builder);
while (PHINode *PN = dyn_cast<PHINode>(BB->begin())) {
if (isa<FPMathOperator>(PN))
Builder.setFastMathFlags(PN->getFastMathFlags());
// Change the PHI node into a select instruction.
Value *TrueVal = PN->getIncomingValue(PN->getIncomingBlock(0) == IfFalse);
Value *FalseVal = PN->getIncomingValue(PN->getIncomingBlock(0) == IfTrue);

View File

@ -16,7 +16,7 @@ define double @fdiv_test(double %a, double %b) {
; ALL-NEXT: entry:
; ALL-NEXT: [[CMP:%.*]] = fcmp ogt double [[A:%.*]], 0.000000e+00
; ALL-NEXT: [[DIV:%.*]] = fdiv double [[B:%.*]], [[A]]
; ALL-NEXT: [[COND:%.*]] = select i1 [[CMP]], double [[DIV]], double 0.000000e+00
; ALL-NEXT: [[COND:%.*]] = select nsz i1 [[CMP]], double [[DIV]], double 0.000000e+00
; ALL-NEXT: ret double [[COND]]
;
entry:
@ -37,7 +37,7 @@ define void @sqrt_test(float addrspace(1)* noalias nocapture %out, float %a) nou
; ALL-NEXT: entry:
; ALL-NEXT: [[CMP_I:%.*]] = fcmp olt float [[A:%.*]], 0.000000e+00
; ALL-NEXT: [[TMP0:%.*]] = tail call float @llvm.sqrt.f32(float [[A]]) #2
; ALL-NEXT: [[COND_I:%.*]] = select i1 [[CMP_I]], float 0x7FF8000000000000, float [[TMP0]]
; ALL-NEXT: [[COND_I:%.*]] = select afn i1 [[CMP_I]], float 0x7FF8000000000000, float [[TMP0]]
; ALL-NEXT: store float [[COND_I]], float addrspace(1)* [[OUT:%.*]], align 4
; ALL-NEXT: ret void
;
@ -60,7 +60,7 @@ define void @fabs_test(float addrspace(1)* noalias nocapture %out, float %a) nou
; ALL-NEXT: entry:
; ALL-NEXT: [[CMP_I:%.*]] = fcmp olt float [[A:%.*]], 0.000000e+00
; ALL-NEXT: [[TMP0:%.*]] = tail call float @llvm.fabs.f32(float [[A]]) #2
; ALL-NEXT: [[COND_I:%.*]] = select i1 [[CMP_I]], float 0x7FF8000000000000, float [[TMP0]]
; ALL-NEXT: [[COND_I:%.*]] = select reassoc i1 [[CMP_I]], float 0x7FF8000000000000, float [[TMP0]]
; ALL-NEXT: store float [[COND_I]], float addrspace(1)* [[OUT:%.*]], align 4
; ALL-NEXT: ret void
;
@ -83,7 +83,7 @@ define void @fma_test(float addrspace(1)* noalias nocapture %out, float %a, floa
; ALL-NEXT: entry:
; ALL-NEXT: [[CMP_I:%.*]] = fcmp olt float [[A:%.*]], 0.000000e+00
; ALL-NEXT: [[TMP0:%.*]] = tail call float @llvm.fma.f32(float [[A]], float [[B:%.*]], float [[C:%.*]]) #2
; ALL-NEXT: [[COND_I:%.*]] = select i1 [[CMP_I]], float 0x7FF8000000000000, float [[TMP0]]
; ALL-NEXT: [[COND_I:%.*]] = select reassoc nsz i1 [[CMP_I]], float 0x7FF8000000000000, float [[TMP0]]
; ALL-NEXT: store float [[COND_I]], float addrspace(1)* [[OUT:%.*]], align 4
; ALL-NEXT: ret void
;
@ -106,7 +106,7 @@ define void @fmuladd_test(float addrspace(1)* noalias nocapture %out, float %a,
; ALL-NEXT: entry:
; ALL-NEXT: [[CMP_I:%.*]] = fcmp olt float [[A:%.*]], 0.000000e+00
; ALL-NEXT: [[TMP0:%.*]] = tail call float @llvm.fmuladd.f32(float [[A]], float [[B:%.*]], float [[C:%.*]]) #2
; ALL-NEXT: [[COND_I:%.*]] = select i1 [[CMP_I]], float 0x7FF8000000000000, float [[TMP0]]
; ALL-NEXT: [[COND_I:%.*]] = select ninf i1 [[CMP_I]], float 0x7FF8000000000000, float [[TMP0]]
; ALL-NEXT: store float [[COND_I]], float addrspace(1)* [[OUT:%.*]], align 4
; ALL-NEXT: ret void
;
@ -152,7 +152,7 @@ define void @maxnum_test(float addrspace(1)* noalias nocapture %out, float %a, f
; ALL-NEXT: entry:
; ALL-NEXT: [[CMP_I:%.*]] = fcmp olt float [[A:%.*]], 0.000000e+00
; ALL-NEXT: [[TMP0:%.*]] = tail call float @llvm.maxnum.f32(float [[A]], float [[B:%.*]]) #2
; ALL-NEXT: [[COND_I:%.*]] = select i1 [[CMP_I]], float 0x7FF8000000000000, float [[TMP0]]
; ALL-NEXT: [[COND_I:%.*]] = select ninf nsz i1 [[CMP_I]], float 0x7FF8000000000000, float [[TMP0]]
; ALL-NEXT: store float [[COND_I]], float addrspace(1)* [[OUT:%.*]], align 4
; ALL-NEXT: ret void
;
@ -175,7 +175,7 @@ define void @minimum_test(float addrspace(1)* noalias nocapture %out, float %a,
; ALL-NEXT: entry:
; ALL-NEXT: [[CMP_I:%.*]] = fcmp olt float [[A:%.*]], 0.000000e+00
; ALL-NEXT: [[TMP0:%.*]] = tail call float @llvm.minimum.f32(float [[A]], float [[B:%.*]]) #2
; ALL-NEXT: [[COND_I:%.*]] = select i1 [[CMP_I]], float 0x7FF8000000000000, float [[TMP0]]
; ALL-NEXT: [[COND_I:%.*]] = select reassoc i1 [[CMP_I]], float 0x7FF8000000000000, float [[TMP0]]
; ALL-NEXT: store float [[COND_I]], float addrspace(1)* [[OUT:%.*]], align 4
; ALL-NEXT: ret void
;
@ -198,7 +198,7 @@ define void @maximum_test(float addrspace(1)* noalias nocapture %out, float %a,
; ALL-NEXT: entry:
; ALL-NEXT: [[CMP_I:%.*]] = fcmp olt float [[A:%.*]], 0.000000e+00
; ALL-NEXT: [[TMP0:%.*]] = tail call float @llvm.maximum.f32(float [[A]], float [[B:%.*]]) #2
; ALL-NEXT: [[COND_I:%.*]] = select i1 [[CMP_I]], float 0x7FF8000000000000, float [[TMP0]]
; ALL-NEXT: [[COND_I:%.*]] = select nsz i1 [[CMP_I]], float 0x7FF8000000000000, float [[TMP0]]
; ALL-NEXT: store float [[COND_I]], float addrspace(1)* [[OUT:%.*]], align 4
; ALL-NEXT: ret void
;