[Mem2Reg] Respect optnone
authorJames Molloy <james.molloy@arm.com>
Fri, 11 Dec 2015 13:36:59 +0000 (13:36 +0000)
committerJames Molloy <james.molloy@arm.com>
Fri, 11 Dec 2015 13:36:59 +0000 (13:36 +0000)
Mem2Reg shouldn't be optimizing a function that is marked
optnone. There is a test checking this that fails when mem2reg is
explicitly added to the standard pass pipeline.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@255336 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Utils/Mem2Reg.cpp
test/Transforms/Mem2Reg/optnone.ll [new file with mode: 0644]

index 00cf4e6c01c8a9c22f1ff78e20e3f458ae37f0dd..aa1e35ddba024f458e3d2241c65b31d1fe361c80 100644 (file)
@@ -63,6 +63,9 @@ bool PromotePass::runOnFunction(Function &F) {
 
   BasicBlock &BB = F.getEntryBlock();  // Get the entry node for the function
 
+  if (F.hasFnAttribute(Attribute::OptimizeNone))
+    return false;
+
   bool Changed  = false;
 
   DominatorTree &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
diff --git a/test/Transforms/Mem2Reg/optnone.ll b/test/Transforms/Mem2Reg/optnone.ll
new file mode 100644 (file)
index 0000000..41ee77a
--- /dev/null
@@ -0,0 +1,21 @@
+; RUN: opt < %s -mem2reg -S | FileCheck %s
+
+; This function is optnone, so the allocas should not be eliminated.
+
+; CHECK-LABEL: @testfunc
+; CHECK: alloca
+; CHECK: alloca
+define double @testfunc(i32 %i, double %j) optnone noinline {
+       %I = alloca i32         ; <i32*> [#uses=4]
+       %J = alloca double              ; <double*> [#uses=2]
+       store i32 %i, i32* %I
+       store double %j, double* %J
+       %t1 = load i32, i32* %I         ; <i32> [#uses=1]
+       %t2 = add i32 %t1, 1            ; <i32> [#uses=1]
+       store i32 %t2, i32* %I
+       %t3 = load i32, i32* %I         ; <i32> [#uses=1]
+       %t4 = sitofp i32 %t3 to double          ; <double> [#uses=1]
+       %t5 = load double, double* %J           ; <double> [#uses=1]
+       %t6 = fmul double %t4, %t5              ; <double> [#uses=1]
+       ret double %t6
+}