I expect that Options.EnableFastISel
is false by default when the target does not implement FastISel.
Example:
target datalayout = "E-m:e-i1:8:16-i8:8:16-i64:64-f128:64-a:8:16-n32:64"
target triple = "s390x-unknown-linux"
define dso_local signext i32 @bug() #0 {
entry:
ret i32 0
}
attributes #0 = { noinline nounwind optnone sspreq "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="z10" }
With llc < bug.ll -stop-after=stack-protector
the resulting IR is:
define dso_local signext i32 @bug() #0 {
entry:
%StackGuardSlot = alloca i8*, align 8
%0 = call i8* @llvm.stackguard()
call void @llvm.stackprotector(i8* %0, i8** %StackGuardSlot)
ret i32 0
}
In the SelectionDAG implementation of the stack protector feature, the check for the stack failure is inserted during lowering.
But with llc < bug.ll -stop-after=stack-protector -O0
the check gets inserted:
define dso_local signext i32 @bug() #0 {
entry:
%StackGuardSlot = alloca i8*, align 8
%0 = call i8* @llvm.stackguard()
call void @llvm.stackprotector(i8* %0, i8** %StackGuardSlot)
%1 = call i8* @llvm.stackguard()
%2 = load volatile i8*, i8** %StackGuardSlot, align 8
%3 = icmp eq i8* %1, %2
br i1 %3, label %SP_return, label %CallStackCheckFailBlk, !prof !0
SP_return: ; preds = %entry
ret i32 0
CallStackCheckFailBlk: ; preds = %entry
call void @__stack_chk_fail()
unreachable
}
This output does not change when I additionally specify -enable-selectiondag-sp
on the command line.
The condition in StackProtector::InsertStackProtectors()
is:
bool SupportsSelectionDAGSP =
TLI->useStackGuardXorFP() ||
(EnableSelectionDAGSP && !TM->Options.EnableFastISel);
TLI->useStackGuardXorFP()
is false
because the SystemZ target does not use it. EnableSelectionDAGSP
is true
when I specify -enable-selectiondag-sp
on the command line. Since the fastisel code is generated, the flag TM->Options.EnableFastISel
must be true
in this case. I checked this with adding a llvm::dbgs()
statement.
I’m not sure if it is a bug. My expectation is that the EnableFastISel
flag (and the O0WantsFastISel
flag in the TargetMachine
class) only takes a true
value if the target has a FastISel implementation.