llvm.org GIT mirror llvm / 63813a4
[SCCP] Add UnaryOperator visitor to SCCP for unary FNeg Differential Revision: https://reviews.llvm.org/D62819 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@362449 91177308-0d34-0410-b5e6-96231b3b80d8 Cameron McInally 3 months ago
3 changed file(s) with 67 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
612612
613613 void visitCastInst(CastInst &I);
614614 void visitSelectInst(SelectInst &I);
615 void visitUnaryOperator(Instruction &I);
615616 void visitBinaryOperator(Instruction &I);
616617 void visitCmpInst(CmpInst &I);
617618 void visitExtractValueInst(ExtractValueInst &EVI);
968969 markOverdefined(&I);
969970 }
970971
972 // Handle Unary Operators.
973 void SCCPSolver::visitUnaryOperator(Instruction &I) {
974 LatticeVal V0State = getValueState(I.getOperand(0));
975
976 LatticeVal &IV = ValueState[&I];
977 if (IV.isOverdefined()) return;
978
979 if (V0State.isConstant()) {
980 Constant *C = ConstantExpr::get(I.getOpcode(), V0State.getConstant());
981
982 // op Y -> undef.
983 if (isa(C))
984 return;
985 return (void)markConstant(IV, &I, C);
986 }
987
988 // If something is undef, wait for it to resolve.
989 if (!V0State.isOverdefined())
990 return;
991
992 markOverdefined(&I);
993 }
994
971995 // Handle Binary Operators.
972996 void SCCPSolver::visitBinaryOperator(Instruction &I) {
973997 LatticeVal V1State = getValueState(I.getOperand(0));
14831507 else
14841508 markOverdefined(&I);
14851509 return true;
1510 case Instruction::FNeg:
1511 break; // fneg undef -> undef
14861512 case Instruction::ZExt:
14871513 case Instruction::SExt:
14881514 case Instruction::FPToUI:
0 ; This is a basic sanity check for constant propagation. The fneg instruction
1 ; should be eliminated.
2
3 ; RUN: opt < %s -sccp -S | FileCheck %s
4
5 define double @test(i1 %B) {
6 br i1 %B, label %BB1, label %BB2
7 BB1:
8 %Val = fneg double 42.0
9 br label %BB3
10 BB2:
11 br label %BB3
12 BB3:
13 %Ret = phi double [%Val, %BB1], [1.0, %BB2]
14 ret double %Ret
15 ; CHECK-LABEL: @test(
16 ; CHECK: [[PHI:%.*]] = phi double [ -4.200000e+01, %BB1 ], [ 1.000000e+00, %BB2 ]
17 }
18
19 define double @test1(i1 %B) {
20 br i1 %B, label %BB1, label %BB2
21 BB1:
22 %Div = fdiv double 1.0, 1.0
23 %Val = fneg double %Div
24 br label %BB3
25 BB2:
26 br label %BB3
27 BB3:
28 %Ret = phi double [%Val, %BB1], [1.0, %BB2]
29 ret double %Ret
30 ; CHECK-LABEL: @test1(
31 ; CHECK: [[PHI:%.*]] = phi double [ -1.000000e+00, %BB1 ], [ 1.000000e+00, %BB2 ]
32 }
179179 ; CHECK-LABEL: @test11(
180180 ; CHECK: ret i32 0
181181 }
182
183 ; Test unary ops
184 define double @test12(double %x) {
185 %t = fneg double undef
186 ret double %t
187 ; CHECK-LABEL: @test12(
188 ; CHECK: double undef
189 }