[PATCH] D55499: [PowerPC] intrinsic llvm.eh.sjlj.setjmp should not have flag isBarrier.

ChenZheng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 9 17:33:06 PST 2018


shchenz created this revision.
shchenz added reviewers: hfinkel, kbarton, jsji, t.p.northover.
Herald added subscribers: hiraditya, kristof.beyls, javed.absar, nemanjai.

This is an issue found when testing PowerPC with verify-machineinstrs.

llc -mtriple=powerpc64-unknown-linux-gnu < llvm/llvm/test/CodeGen/PowerPC/sj-ctr-loop.ll -verify-machineinstrs

Bad machine code: MBB exits via unconditional fall-through but ends with a barrier instruction! ***

  function: main
  basic block: %bb.2 for.body.lr.ph (0x100275437e8)

Content in block BB.2:

BB#2: derived from LLVM BB %for.end
Predecessors according to CFG: BB#1
%vreg2<def> = ADDIStocHA %X2, <ga:@env_sigill>; G8RC_and_G8RC_NOX0:%vreg2
%vreg3<def> = LDtocL <ga:@env_sigill>, %vreg2<kill>; mem:LD8[GOT] G8RC:%vreg3 G8RC_and_G8RC_NOX0:%vreg2
%vreg4<def> = EH_SjLj_SetJmp64 %vreg3<kill>, %CTR8<imp-def,dead>; GPRC:%vreg4 G8RC:%vreg3

A barrier instruction means control flow can not fall through like llvm.eh.sjlj.longjmp and unconditional jumps. But setjmp should fall through. intrinsic llvm.eh.sjlj.setjmp should not have flag isBarrier.

The original case fails at another place after resolving setjmp barrier issue. So I create a new case. And I only focus on PowerPC target, there are some other platforms like ARM, X86 also have same issue.


https://reviews.llvm.org/D55499

Files:
  llvm/lib/Target/PowerPC/PPCInstr64Bit.td
  llvm/lib/Target/PowerPC/PPCInstrInfo.td
  llvm/test/CodeGen/PowerPC/sjlj.ll


Index: llvm/test/CodeGen/PowerPC/sjlj.ll
===================================================================
--- llvm/test/CodeGen/PowerPC/sjlj.ll
+++ llvm/test/CodeGen/PowerPC/sjlj.ll
@@ -1,5 +1,5 @@
-; RUN: llc < %s -mtriple=powerpc64-unknown-linux-gnu -mcpu=pwr7 | FileCheck %s
-; RUN: llc < %s -mtriple=powerpc64-unknown-linux-gnu -mcpu=a2 | FileCheck -check-prefix=CHECK-NOAV %s
+; RUN: llc < %s -mtriple=powerpc64-unknown-linux-gnu -mcpu=pwr7 -verify-machineinstrs | FileCheck %s
+; RUN: llc < %s -mtriple=powerpc64-unknown-linux-gnu -mcpu=a2 -verify-machineinstrs | FileCheck -check-prefix=CHECK-NOAV %s
 target datalayout = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-f128:128:128-v128:128:128-n32:64"
 target triple = "powerpc64-unknown-linux-gnu"
 
@@ -7,6 +7,7 @@
 %struct.__sigset_t = type { [16 x i64] }
 
 @env_sigill = internal global [1 x %struct.__jmp_buf_tag] zeroinitializer, align 16
+ at cond = external global i8, align 1
 
 define void @foo() #0 {
 entry:
@@ -145,6 +146,23 @@
 ; CHECK: blr
 }
 
+define void @test_sjlj_setjmp() #0 {
+entry:
+  %0 = load i8, i8* @cond, align 1
+  %tobool = trunc i8 %0 to i1
+  br i1 %tobool, label %return, label %end
+
+end:
+  %1 = call i32 @llvm.eh.sjlj.setjmp(i8* bitcast ([1 x %struct.__jmp_buf_tag]* @env_sigill to i8*))
+  br label %return
+
+return:
+  ret void
+
+; CHECK-LABEL: test_sjlj_setjmp:
+; CHECK-NOT: bl _setjmp ; intrinsic llvm.eh.sjlj.setjmp does not call buildin function _setjmp.
+}
+
 declare void @bar(i8*) #3
 
 declare i8* @llvm.frameaddress(i32) #2
Index: llvm/lib/Target/PowerPC/PPCInstrInfo.td
===================================================================
--- llvm/lib/Target/PowerPC/PPCInstrInfo.td
+++ llvm/lib/Target/PowerPC/PPCInstrInfo.td
@@ -1550,12 +1550,15 @@
 
 }
 
-let hasSideEffects = 1, isBarrier = 1, usesCustomInserter = 1 in {
+let hasSideEffects = 1, usesCustomInserter = 1 in {
   let Defs = [CTR] in
   def EH_SjLj_SetJmp32  : Pseudo<(outs gprc:$dst), (ins memr:$buf),
                             "#EH_SJLJ_SETJMP32",
                             [(set i32:$dst, (PPCeh_sjlj_setjmp addr:$buf))]>,
                           Requires<[In32BitMode]>;
+}
+
+let hasSideEffects = 1, isBarrier = 1, usesCustomInserter = 1 in {
   let isTerminator = 1 in
   def EH_SjLj_LongJmp32 : Pseudo<(outs), (ins memr:$buf),
                             "#EH_SJLJ_LONGJMP32",
Index: llvm/lib/Target/PowerPC/PPCInstr64Bit.td
===================================================================
--- llvm/lib/Target/PowerPC/PPCInstr64Bit.td
+++ llvm/lib/Target/PowerPC/PPCInstr64Bit.td
@@ -347,12 +347,15 @@
 } // hasExtraSrcRegAllocReq = 1
 } // hasSideEffects = 0
 
-let hasSideEffects = 1, isBarrier = 1, usesCustomInserter = 1 in {
+let hasSideEffects = 1, usesCustomInserter = 1 in {
   let Defs = [CTR8] in
   def EH_SjLj_SetJmp64  : Pseudo<(outs gprc:$dst), (ins memr:$buf),
                             "#EH_SJLJ_SETJMP64",
                             [(set i32:$dst, (PPCeh_sjlj_setjmp addr:$buf))]>,
                           Requires<[In64BitMode]>;
+}
+
+let hasSideEffects = 1, isBarrier = 1, usesCustomInserter = 1 in {
   let isTerminator = 1 in
   def EH_SjLj_LongJmp64 : Pseudo<(outs), (ins memr:$buf),
                             "#EH_SJLJ_LONGJMP64",


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55499.177449.patch
Type: text/x-patch
Size: 3297 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181210/4f5549ec/attachment.bin>


More information about the llvm-commits mailing list