llvm.org GIT mirror llvm / 2adc29e
Merging r276389: ------------------------------------------------------------------------ r276389 | majnemer | 2016-07-21 21:54:44 -0700 (Thu, 21 Jul 2016) | 6 lines Don't remove side effecting instructions due to ConstantFoldInstruction Just because we can constant fold the result of an instruction does not imply that we can delete the instruction. It may have side effects. This fixes PR28655. ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_39@276660 91177308-0d34-0410-b5e6-96231b3b80d8 Hans Wennborg 4 years ago
8 changed file(s) with 74 addition(s) and 51 deletion(s). Raw diff Collapse all Expand all
4343 #include "llvm/Transforms/Utils/CtorUtils.h"
4444 #include "llvm/Transforms/Utils/Evaluator.h"
4545 #include "llvm/Transforms/Utils/GlobalStatus.h"
46 #include "llvm/Transforms/Utils/Local.h"
4647 #include
4748 using namespace llvm;
4849
778779 // Instructions could multiply use V.
779780 while (UI != E && *UI == I)
780781 ++UI;
781 I->eraseFromParent();
782 if (isInstructionTriviallyDead(I, TLI))
783 I->eraseFromParent();
782784 }
783785 }
784786
28292829 // Add operands to the worklist.
28302830 replaceInstUsesWith(*I, C);
28312831 ++NumConstProp;
2832 eraseInstFromFunction(*I);
2832 if (isInstructionTriviallyDead(I, TLI))
2833 eraseInstFromFunction(*I);
28332834 MadeIRChange = true;
28342835 continue;
28352836 }
28502851 // Add operands to the worklist.
28512852 replaceInstUsesWith(*I, C);
28522853 ++NumConstProp;
2853 eraseInstFromFunction(*I);
2854 if (isInstructionTriviallyDead(I, TLI))
2855 eraseInstFromFunction(*I);
28542856 MadeIRChange = true;
28552857 continue;
28562858 }
30063008 << *Inst << '\n');
30073009 Inst->replaceAllUsesWith(C);
30083010 ++NumConstProp;
3009 Inst->eraseFromParent();
3011 if (isInstructionTriviallyDead(Inst, TLI))
3012 Inst->eraseFromParent();
30103013 continue;
30113014 }
30123015
1818 //===----------------------------------------------------------------------===//
1919
2020 #include "llvm/Transforms/Scalar.h"
21 #include "llvm/Transforms/Utils/Local.h"
2122 #include "llvm/ADT/Statistic.h"
2223 #include "llvm/Analysis/ConstantFolding.h"
2324 #include "llvm/IR/Constant.h"
8990
9091 // Remove the dead instruction.
9192 WorkList.erase(I);
92 I->eraseFromParent();
93 if (isInstructionTriviallyDead(I, TLI)) {
94 I->eraseFromParent();
95 ++NumInstKilled;
96 }
9397
9498 // We made a change to the function...
9599 Changed = true;
96 ++NumInstKilled;
97100 }
98101 }
99102 return Changed;
757757 ConstantFoldInstruction(I, BB->getModule()->getDataLayout(), TLI);
758758 if (SimpleVal) {
759759 I->replaceAllUsesWith(SimpleVal);
760 I->eraseFromParent();
760 if (isInstructionTriviallyDead(I, TLI))
761 I->eraseFromParent();
761762 Condition = SimpleVal;
762763 }
763764 }
376376 &I, I.getModule()->getDataLayout(), TLI)) {
377377 DEBUG(dbgs() << "LICM folding inst: " << I << " --> " << *C << '\n');
378378 CurAST->copyValue(&I, C);
379 CurAST->deleteValue(&I);
380379 I.replaceAllUsesWith(C);
381 I.eraseFromParent();
380 if (isInstructionTriviallyDead(&I, TLI)) {
381 CurAST->deleteValue(&I);
382 I.eraseFromParent();
383 }
382384 continue;
383385 }
384386
0 ; RUN: opt < %s -constprop -S | FileCheck %s
11 ; RUN: opt < %s -constprop -disable-simplify-libcalls -S | FileCheck %s --check-prefix=FNOBUILTIN
22
3 declare double @acos(double)
4 declare double @asin(double)
5 declare double @atan(double)
6 declare double @atan2(double, double)
7 declare double @ceil(double)
8 declare double @cos(double)
9 declare double @cosh(double)
10 declare double @exp(double)
11 declare double @exp2(double)
12 declare double @fabs(double)
13 declare double @floor(double)
14 declare double @fmod(double, double)
15 declare double @log(double)
16 declare double @log10(double)
17 declare double @pow(double, double)
18 declare double @sin(double)
19 declare double @sinh(double)
20 declare double @sqrt(double)
21 declare double @tan(double)
22 declare double @tanh(double)
23
24 declare float @acosf(float)
25 declare float @asinf(float)
26 declare float @atanf(float)
27 declare float @atan2f(float, float)
28 declare float @ceilf(float)
29 declare float @cosf(float)
30 declare float @coshf(float)
31 declare float @expf(float)
32 declare float @exp2f(float)
33 declare float @fabsf(float)
34 declare float @floorf(float)
35 declare float @fmodf(float, float)
36 declare float @logf(float)
37 declare float @log10f(float)
38 declare float @powf(float, float)
39 declare float @sinf(float)
40 declare float @sinhf(float)
41 declare float @sqrtf(float)
42 declare float @tanf(float)
43 declare float @tanhf(float)
3 declare double @acos(double) readnone nounwind
4 declare double @asin(double) readnone nounwind
5 declare double @atan(double) readnone nounwind
6 declare double @atan2(double, double) readnone nounwind
7 declare double @ceil(double) readnone nounwind
8 declare double @cos(double) readnone nounwind
9 declare double @cosh(double) readnone nounwind
10 declare double @exp(double) readnone nounwind
11 declare double @exp2(double) readnone nounwind
12 declare double @fabs(double) readnone nounwind
13 declare double @floor(double) readnone nounwind
14 declare double @fmod(double, double) readnone nounwind
15 declare double @log(double) readnone nounwind
16 declare double @log10(double) readnone nounwind
17 declare double @pow(double, double) readnone nounwind
18 declare double @sin(double) readnone nounwind
19 declare double @sinh(double) readnone nounwind
20 declare double @sqrt(double) readnone nounwind
21 declare double @tan(double) readnone nounwind
22 declare double @tanh(double) readnone nounwind
23
24 declare float @acosf(float) readnone nounwind
25 declare float @asinf(float) readnone nounwind
26 declare float @atanf(float) readnone nounwind
27 declare float @atan2f(float, float) readnone nounwind
28 declare float @ceilf(float) readnone nounwind
29 declare float @cosf(float) readnone nounwind
30 declare float @coshf(float) readnone nounwind
31 declare float @expf(float) readnone nounwind
32 declare float @exp2f(float) readnone nounwind
33 declare float @fabsf(float) readnone nounwind
34 declare float @floorf(float) readnone nounwind
35 declare float @fmodf(float, float) readnone nounwind
36 declare float @logf(float) readnone nounwind
37 declare float @log10f(float) readnone nounwind
38 declare float @powf(float, float) readnone nounwind
39 declare float @sinf(float) readnone nounwind
40 declare float @sinhf(float) readnone nounwind
41 declare float @sqrtf(float) readnone nounwind
42 declare float @tanf(float) readnone nounwind
43 declare float @tanhf(float) readnone nounwind
4444
4545 define double @T() {
4646 ; CHECK-LABEL: @T(
275275 %X = call <2 x i16> bitcast (i32 ()* @test16a to <2 x i16> ()*)( )
276276 ret <2 x i16> %X
277277 }
278
279 declare i32 @pr28655(i32 returned %V)
280
281 define i32 @test17() {
282 entry:
283 %C = call i32 @pr28655(i32 0)
284 ret i32 %C
285 }
286 ; CHECK-LABEL: @test17(
287 ; CHECK: call i32 @pr28655(i32 0)
288 ; CHECK: ret i32 0
5454 ; CHECK-NEXT: %call3 = call fast double @log(double %call2)
5555 ; CHECK-NEXT: ret double %call3
5656
57 declare double @log(double)
57 declare double @log(double) #0
5858 declare double @exp2(double)
5959 declare double @llvm.pow.f64(double, double)
6060
61 attributes #0 = { nounwind readnone }