[PATCH] D62699: [InlineCost] Add support for unary fneg.
Phabricator via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 6 11:59:32 PDT 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rL362732: [InlineCost] Add support for unary fneg. (authored by ctopper, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D62699?vs=203390&id=203413#toc
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D62699/new/
https://reviews.llvm.org/D62699
Files:
llvm/trunk/lib/Analysis/InlineCost.cpp
llvm/trunk/test/Transforms/Inline/inline_constprop.ll
Index: llvm/trunk/lib/Analysis/InlineCost.cpp
===================================================================
--- llvm/trunk/lib/Analysis/InlineCost.cpp
+++ llvm/trunk/lib/Analysis/InlineCost.cpp
@@ -273,6 +273,7 @@
bool visitCmpInst(CmpInst &I);
bool visitSub(BinaryOperator &I);
bool visitBinaryOperator(BinaryOperator &I);
+ bool visitFNeg(UnaryOperator &I);
bool visitLoad(LoadInst &I);
bool visitStore(StoreInst &I);
bool visitExtractValue(ExtractValueInst &I);
@@ -1106,6 +1107,28 @@
return false;
}
+bool CallAnalyzer::visitFNeg(UnaryOperator &I) {
+ Value *Op = I.getOperand(0);
+ Constant *COp = dyn_cast<Constant>(Op);
+ if (!COp)
+ COp = SimplifiedValues.lookup(Op);
+
+ Value *SimpleV = SimplifyFNegInst(COp ? COp : Op,
+ cast<FPMathOperator>(I).getFastMathFlags(),
+ DL);
+
+ if (Constant *C = dyn_cast_or_null<Constant>(SimpleV))
+ SimplifiedValues[&I] = C;
+
+ if (SimpleV)
+ return true;
+
+ // Disable any SROA on arguments to arbitrary, unsimplified fneg.
+ disableSROA(Op);
+
+ return false;
+}
+
bool CallAnalyzer::visitLoad(LoadInst &I) {
Value *SROAArg;
DenseMap<Value *, int>::iterator CostIt;
Index: llvm/trunk/test/Transforms/Inline/inline_constprop.ll
===================================================================
--- llvm/trunk/test/Transforms/Inline/inline_constprop.ll
+++ llvm/trunk/test/Transforms/Inline/inline_constprop.ll
@@ -345,3 +345,34 @@
; CHECK-LABEL: define void @caller7(
; CHECK: %call = call i16 @caller7.external(i16 1)
; CHECK-NEXT: ret void
+
+define float @caller8(float %y) {
+; Check that we can constant-prop through fneg instructions
+;
+; CHECK-LABEL: @caller8(
+; CHECK-NOT: call
+; CHECK: ret
+ %x = call float @callee8(float -42.0, float %y)
+ ret float %x
+}
+
+define float @callee8(float %x, float %y) {
+ %neg = fneg float %x
+ %icmp = fcmp ugt float %neg, 42.0
+ br i1 %icmp, label %bb.true, label %bb.false
+
+bb.true:
+ ; This block musn't be counted in the inline cost.
+ %y1 = fadd float %y, 1.0
+ %y2 = fadd float %y1, 1.0
+ %y3 = fadd float %y2, 1.0
+ %y4 = fadd float %y3, 1.0
+ %y5 = fadd float %y4, 1.0
+ %y6 = fadd float %y5, 1.0
+ %y7 = fadd float %y6, 1.0
+ %y8 = fadd float %y7, 1.0
+ ret float %y8
+
+bb.false:
+ ret float %x
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62699.203413.patch
Type: text/x-patch
Size: 2353 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190606/244bb91e/attachment.bin>
More information about the llvm-commits
mailing list