[PATCH] D33519: [PPC] Lower llvm.ppc.cfence(constant) to no-op.

Tim Shen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 24 13:52:52 PDT 2017


timshen created this revision.
Herald added a subscriber: nemanjai.

As the test case shows, if a pass constant-fold the generated
llvm.ppc.cfence(%tmp) to llvm.ppc.cfence(0), cfence should lower to
nothing, instead of crash later in legalization.


https://reviews.llvm.org/D33519

Files:
  llvm/lib/Target/PowerPC/PPCISelLowering.cpp
  llvm/test/CodeGen/PowerPC/atomics-constant.ll


Index: llvm/test/CodeGen/PowerPC/atomics-constant.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/PowerPC/atomics-constant.ll
@@ -0,0 +1,19 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc < %s | FileCheck %s
+
+target triple = "powerpc64le-linux-gnu"
+
+ at a = constant i64 zeroinitializer
+
+define i64 @foo() {
+; CHECK-LABEL: foo:
+; CHECK:       # BB#0: # %entry
+; CHECK-NEXT:    addis 3, 2, .LC0 at toc@ha
+; CHECK-NEXT:    ld 3, .LC0 at toc@l(3)
+; CHECK-NEXT:    ld 3, 0(3)
+; CHECK-NEXT:    li 3, 0
+; CHECK-NEXT:    blr
+entry:
+  %value = load atomic i64, i64* @a acquire, align 8
+  ret i64 %value
+}
Index: llvm/lib/Target/PowerPC/PPCISelLowering.cpp
===================================================================
--- llvm/lib/Target/PowerPC/PPCISelLowering.cpp
+++ llvm/lib/Target/PowerPC/PPCISelLowering.cpp
@@ -8212,6 +8212,12 @@
   SDLoc DL(Op);
   switch (cast<ConstantSDNode>(Op.getOperand(ArgStart))->getZExtValue()) {
   case Intrinsic::ppc_cfence: {
+    assert(ArgStart == 1);
+    // If the operand is a constant (e.g. load from a constant pool being
+    // constant folded), there is no need to form a fence.
+    if (isa<ConstantSDNode>(Op.getOperand(ArgStart + 1))) {
+      return Op.getOperand(0);
+    }
     assert(Subtarget.isPPC64() && "Only 64-bit is supported for now.");
     return SDValue(DAG.getMachineNode(PPC::CFENCE8, DL, MVT::Other,
                                       DAG.getNode(ISD::ANY_EXTEND, DL, MVT::i64,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33519.100160.patch
Type: text/x-patch
Size: 1561 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170524/72b7957c/attachment.bin>


More information about the llvm-commits mailing list