diff --git a/llvm/lib/Target/ARM/ARMTargetMachine.cpp b/llvm/lib/Target/ARM/ARMTargetMachine.cpp index bd29a052c372..e794fb71af63 100644 --- a/llvm/lib/Target/ARM/ARMTargetMachine.cpp +++ b/llvm/lib/Target/ARM/ARMTargetMachine.cpp @@ -402,6 +402,9 @@ void ARMPassConfig::addPreEmitPass() { if (getARMSubtarget().isThumb2()) addPass(&UnpackMachineBundlesID); - addPass(createARMOptimizeBarriersPass()); + // Don't optimize barriers at -O0. + if (getOptLevel() != CodeGenOpt::None) + addPass(createARMOptimizeBarriersPass()); + addPass(createARMConstantIslandPass()); } diff --git a/llvm/test/CodeGen/ARM/noopt-dmb-v7.ll b/llvm/test/CodeGen/ARM/noopt-dmb-v7.ll new file mode 100644 index 000000000000..56a29c8a17e8 --- /dev/null +++ b/llvm/test/CodeGen/ARM/noopt-dmb-v7.ll @@ -0,0 +1,15 @@ +; Ensure that adjacent duplicated barriers are not removed at -O0. +; RUN: llc -O0 < %s -mtriple=armv7 -mattr=+db | FileCheck %s + +define i32 @t1() { +entry: + fence seq_cst + fence seq_cst + fence seq_cst + ret i32 0 +} + +; CHECK: @ BB#0: @ %entry +; CHECK-NEXT: dmb ish +; CHECK-NEXT: dmb ish +; CHECK-NEXT: dmb ish diff --git a/llvm/test/CodeGen/ARM/optimize-dmbs-v7.ll b/llvm/test/CodeGen/ARM/optimize-dmbs-v7.ll index 64f5e202d36a..34a55aa718a3 100644 --- a/llvm/test/CodeGen/ARM/optimize-dmbs-v7.ll +++ b/llvm/test/CodeGen/ARM/optimize-dmbs-v7.ll @@ -1,4 +1,4 @@ -; RUN: llc < %s -mtriple=armv7 -mattr=+db | FileCheck %s +; RUN: llc -O1 < %s -mtriple=armv7 -mattr=+db | FileCheck %s @x1 = global i32 0, align 4 @x2 = global i32 0, align 4