Skip to content

Commit 5ea05e5

Browse files
authored
Merge branch 'main' into eng/abhay/machine-verify-early-clobber-fix-tests
2 parents cc04948 + 81dede8 commit 5ea05e5

39 files changed

+440
-252
lines changed

libc/src/__support/OSUtil/linux/fcntl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ ErrorOr<int> fcntl(int fd, int cmd, void *arg) {
6666
LIBC_NAMESPACE::syscall_impl<int>(FCNTL_SYSCALL_ID, fd, cmd, &flk64);
6767
// On failure, return
6868
if (ret < 0)
69-
return Error(-1);
69+
return Error(-ret);
7070
// Check for overflow, i.e. the offsets are not the same when cast
7171
// to off_t from off64_t.
7272
if (static_cast<off_t>(flk64.l_len) != flk64.l_len ||

libc/test/src/fcntl/fcntl_test.cpp

Lines changed: 93 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -94,78 +94,99 @@ TEST_F(LlvmLibcFcntlTest, FcntlSetFl) {
9494
ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));
9595
}
9696

97-
TEST_F(LlvmLibcFcntlTest, FcntlGetLkRead) {
98-
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
99-
constexpr const char *TEST_FILE_NAME = "testdata/fcntl_getlkread.test";
100-
auto TEST_FILE = libc_make_test_file_path(TEST_FILE_NAME);
101-
102-
struct flock flk, svflk;
103-
int retVal;
104-
int fd =
105-
LIBC_NAMESPACE::open(TEST_FILE, O_CREAT | O_TRUNC | O_RDONLY, S_IRWXU);
106-
ASSERT_ERRNO_SUCCESS();
107-
ASSERT_GT(fd, 0);
108-
109-
flk.l_type = F_RDLCK;
110-
flk.l_start = 0;
111-
flk.l_whence = SEEK_SET;
112-
flk.l_len = 50;
113-
114-
// copy flk into svflk
115-
svflk = flk;
116-
117-
retVal = LIBC_NAMESPACE::fcntl(fd, F_GETLK, &svflk);
118-
ASSERT_ERRNO_SUCCESS();
119-
ASSERT_GT(retVal, -1);
120-
ASSERT_NE((int)flk.l_type, F_WRLCK); // File should not be write locked.
121-
122-
retVal = LIBC_NAMESPACE::fcntl(fd, F_SETLK, &svflk);
123-
ASSERT_ERRNO_SUCCESS();
124-
ASSERT_GT(retVal, -1);
125-
126-
ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));
127-
}
128-
129-
TEST_F(LlvmLibcFcntlTest, FcntlGetLkWrite) {
130-
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
131-
constexpr const char *TEST_FILE_NAME = "testdata/fcntl_getlkwrite.test";
132-
auto TEST_FILE = libc_make_test_file_path(TEST_FILE_NAME);
133-
134-
struct flock flk, svflk;
135-
int retVal;
136-
int fd = LIBC_NAMESPACE::open(TEST_FILE, O_CREAT | O_TRUNC | O_RDWR, S_IRWXU);
137-
ASSERT_ERRNO_SUCCESS();
138-
ASSERT_GT(fd, 0);
139-
140-
flk.l_type = F_WRLCK;
141-
flk.l_start = 0;
142-
flk.l_whence = SEEK_SET;
143-
flk.l_len = 0;
144-
145-
// copy flk into svflk
146-
svflk = flk;
147-
148-
retVal = LIBC_NAMESPACE::fcntl(fd, F_GETLK, &svflk);
149-
ASSERT_ERRNO_SUCCESS();
150-
ASSERT_GT(retVal, -1);
151-
ASSERT_NE((int)flk.l_type, F_RDLCK); // File should not be read locked.
152-
153-
retVal = LIBC_NAMESPACE::fcntl(fd, F_SETLK, &svflk);
154-
ASSERT_ERRNO_SUCCESS();
155-
ASSERT_GT(retVal, -1);
156-
157-
ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));
158-
}
159-
160-
TEST_F(LlvmLibcFcntlTest, UseAfterClose) {
161-
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
162-
constexpr const char *TEST_FILE_NAME = "testdata/fcntl_use_after_close.test";
163-
auto TEST_FILE = libc_make_test_file_path(TEST_FILE_NAME);
164-
int fd = LIBC_NAMESPACE::open(TEST_FILE, O_CREAT | O_TRUNC | O_RDWR, S_IRWXU);
165-
ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));
166-
ASSERT_EQ(-1, LIBC_NAMESPACE::fcntl(fd, F_GETFL));
167-
ASSERT_ERRNO_EQ(EBADF);
168-
}
97+
/* Tests that are common between OFD and traditional variants of fcntl locks. */
98+
template <int GETLK_CMD, int SETLK_CMD>
99+
class LibcFcntlCommonLockTests : public LlvmLibcFcntlTest {
100+
public:
101+
void GetLkRead() {
102+
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
103+
constexpr const char *TEST_FILE_NAME = "testdata/fcntl_getlkread.test";
104+
const auto TEST_FILE = libc_make_test_file_path(TEST_FILE_NAME);
105+
106+
struct flock flk = {};
107+
struct flock svflk = {};
108+
int retVal;
109+
int fd =
110+
LIBC_NAMESPACE::open(TEST_FILE, O_CREAT | O_TRUNC | O_RDONLY, S_IRWXU);
111+
ASSERT_ERRNO_SUCCESS();
112+
ASSERT_GT(fd, 0);
113+
114+
flk.l_type = F_RDLCK;
115+
flk.l_start = 0;
116+
flk.l_whence = SEEK_SET;
117+
flk.l_len = 50;
118+
119+
// copy flk into svflk
120+
svflk = flk;
121+
122+
retVal = LIBC_NAMESPACE::fcntl(fd, GETLK_CMD, &svflk);
123+
ASSERT_ERRNO_SUCCESS();
124+
ASSERT_GT(retVal, -1);
125+
ASSERT_NE((int)svflk.l_type, F_WRLCK); // File should not be write locked.
126+
127+
retVal = LIBC_NAMESPACE::fcntl(fd, SETLK_CMD, &svflk);
128+
ASSERT_ERRNO_SUCCESS();
129+
ASSERT_GT(retVal, -1);
130+
131+
ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));
132+
}
133+
134+
void GetLkWrite() {
135+
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
136+
constexpr const char *TEST_FILE_NAME = "testdata/fcntl_getlkwrite.test";
137+
const auto TEST_FILE = libc_make_test_file_path(TEST_FILE_NAME);
138+
139+
struct flock flk = {};
140+
struct flock svflk = {};
141+
int retVal;
142+
int fd =
143+
LIBC_NAMESPACE::open(TEST_FILE, O_CREAT | O_TRUNC | O_RDWR, S_IRWXU);
144+
ASSERT_ERRNO_SUCCESS();
145+
ASSERT_GT(fd, 0);
146+
147+
flk.l_type = F_WRLCK;
148+
flk.l_start = 0;
149+
flk.l_whence = SEEK_SET;
150+
flk.l_len = 0;
151+
152+
// copy flk into svflk
153+
svflk = flk;
154+
155+
retVal = LIBC_NAMESPACE::fcntl(fd, GETLK_CMD, &svflk);
156+
ASSERT_ERRNO_SUCCESS();
157+
ASSERT_GT(retVal, -1);
158+
ASSERT_NE((int)svflk.l_type, F_RDLCK); // File should not be read locked.
159+
160+
retVal = LIBC_NAMESPACE::fcntl(fd, SETLK_CMD, &svflk);
161+
ASSERT_ERRNO_SUCCESS();
162+
ASSERT_GT(retVal, -1);
163+
164+
ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));
165+
}
166+
167+
void UseAfterClose() {
168+
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
169+
constexpr const char *TEST_FILE_NAME =
170+
"testdata/fcntl_use_after_close.test";
171+
const auto TEST_FILE = libc_make_test_file_path(TEST_FILE_NAME);
172+
int fd =
173+
LIBC_NAMESPACE::open(TEST_FILE, O_CREAT | O_TRUNC | O_RDWR, S_IRWXU);
174+
ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));
175+
ASSERT_EQ(-1, LIBC_NAMESPACE::fcntl(fd, GETLK_CMD));
176+
ASSERT_ERRNO_EQ(EBADF);
177+
}
178+
};
179+
180+
#define COMMON_LOCK_TESTS(NAME, GETLK, SETLK) \
181+
using NAME = LibcFcntlCommonLockTests<GETLK, SETLK>; \
182+
TEST_F(NAME, GetLkRead) { GetLkRead(); } \
183+
TEST_F(NAME, GetLkWrite) { GetLkWrite(); } \
184+
TEST_F(NAME, UseAfterClose) { UseAfterClose(); } \
185+
static_assert(true, "Require semicolon.")
186+
187+
COMMON_LOCK_TESTS(LlvmLibcFcntlProcessAssociatedLockTest, F_GETLK, F_SETLK);
188+
COMMON_LOCK_TESTS(LlvmLibcFcntlOpenFileDescriptionLockTest, F_OFD_GETLK,
189+
F_OFD_SETLK);
169190

170191
TEST_F(LlvmLibcFcntlTest, SetGetOwnerTest) {
171192
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;

lldb/packages/Python/lldbsuite/test/make/Makefile.rules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ endif
334334
# library to make ASAN tests work for most users, including the bots.
335335
ifeq "$(OS)" "Darwin"
336336
ifneq "$(ASAN_OPTIONS)" ""
337-
LD_FLAGS += -Wl,-lto_library -Wl,$(shell dirname $(shell xcrun -find clang))/../lib/libLTO.dylib
337+
LDFLAGS += -Wl,-lto_library -Wl,$(shell dirname $(shell xcrun -find clang))/../lib/libLTO.dylib
338338
endif
339339
endif
340340
OBJECTS =

llvm/lib/Target/Sparc/Sparc.td

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ def FeatureSoftFloat : SubtargetFeature<"soft-float", "UseSoftFloat", "true",
9595
def TuneSlowRDPC : SubtargetFeature<"slow-rdpc", "HasSlowRDPC", "true",
9696
"rd %pc, %XX is slow", [FeatureV9]>;
9797

98+
def TuneNoPredictor : SubtargetFeature<"no-predictor", "HasNoPredictor", "true",
99+
"Processor has no branch predictor, branches stall execution", []>;
100+
98101
//==== Features added predmoninantly for LEON subtarget support
99102
include "LeonFeatures.td"
100103

@@ -174,12 +177,15 @@ def : Proc<"ultrasparc3", [FeatureV9, FeatureV8Deprecated, FeatureVIS,
174177
FeatureVIS2],
175178
[TuneSlowRDPC]>;
176179
def : Proc<"niagara", [FeatureV9, FeatureV8Deprecated, FeatureVIS,
177-
FeatureVIS2, FeatureUA2005]>;
180+
FeatureVIS2, FeatureUA2005],
181+
[TuneNoPredictor]>;
178182
def : Proc<"niagara2", [FeatureV9, FeatureV8Deprecated, UsePopc,
179-
FeatureVIS, FeatureVIS2, FeatureUA2005]>;
183+
FeatureVIS, FeatureVIS2, FeatureUA2005],
184+
[TuneNoPredictor]>;
180185
def : Proc<"niagara3", [FeatureV9, FeatureV8Deprecated, UsePopc,
181186
FeatureVIS, FeatureVIS2, FeatureVIS3,
182-
FeatureUA2005, FeatureUA2007]>;
187+
FeatureUA2005, FeatureUA2007],
188+
[TuneNoPredictor]>;
183189
def : Proc<"niagara4", [FeatureV9, FeatureV8Deprecated, UsePopc,
184190
FeatureVIS, FeatureVIS2, FeatureVIS3,
185191
FeatureUA2005, FeatureUA2007, FeatureOSA2011,

llvm/lib/Target/Sparc/SparcISelLowering.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2000,6 +2000,14 @@ SparcTargetLowering::SparcTargetLowering(const TargetMachine &TM,
20002000

20012001
setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::Other, Custom);
20022002

2003+
// Some processors have no branch predictor and have pipelines longer than
2004+
// what can be covered by the delay slot. This results in a stall, so mark
2005+
// branches to be expensive on those processors.
2006+
setJumpIsExpensive(Subtarget->hasNoPredictor());
2007+
// The high cost of branching means that using conditional moves will
2008+
// still be profitable even if the condition is predictable.
2009+
PredictableSelectIsExpensive = !isJumpExpensive();
2010+
20032011
setMinFunctionAlignment(Align(4));
20042012

20052013
computeRegisterProperties(Subtarget->getRegisterInfo());

llvm/lib/Target/X86/X86ISelDAGToDAG.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4728,9 +4728,9 @@ bool X86DAGToDAGISel::tryVPTERNLOG(SDNode *N) {
47284728
auto tryPeelOuterNotWrappingLogic = [&](SDNode *Op) {
47294729
if (Op->getOpcode() == ISD::XOR && Op->hasOneUse() &&
47304730
ISD::isBuildVectorAllOnes(Op->getOperand(1).getNode())) {
4731-
SDValue InnerOp = Op->getOperand(0);
4731+
SDValue InnerOp = getFoldableLogicOp(Op->getOperand(0));
47324732

4733-
if (!getFoldableLogicOp(InnerOp))
4733+
if (!InnerOp)
47344734
return SDValue();
47354735

47364736
N0 = InnerOp.getOperand(0);

llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
#include "llvm/IR/Module.h"
7373
#include "llvm/IR/PassManager.h"
7474
#include "llvm/IR/PatternMatch.h"
75+
#include "llvm/IR/ProfDataUtils.h"
7576
#include "llvm/IR/Type.h"
7677
#include "llvm/IR/User.h"
7778
#include "llvm/IR/Value.h"
@@ -105,6 +106,7 @@ STATISTIC(
105106
STATISTIC(NumShiftUntilZero,
106107
"Number of uncountable loops recognized as 'shift until zero' idiom");
107108

109+
namespace llvm {
108110
bool DisableLIRP::All;
109111
static cl::opt<bool, true>
110112
DisableLIRPAll("disable-" DEBUG_TYPE "-all",
@@ -163,6 +165,10 @@ static cl::opt<bool> ForceMemsetPatternIntrinsic(
163165
cl::desc("Use memset.pattern intrinsic whenever possible"), cl::init(false),
164166
cl::Hidden);
165167

168+
extern cl::opt<bool> ProfcheckDisableMetadataFixes;
169+
170+
} // namespace llvm
171+
166172
namespace {
167173

168174
class LoopIdiomRecognize {
@@ -3199,7 +3205,21 @@ bool LoopIdiomRecognize::recognizeShiftUntilBitTest() {
31993205
// The loop trip count check.
32003206
auto *IVCheck = Builder.CreateICmpEQ(IVNext, LoopTripCount,
32013207
CurLoop->getName() + ".ivcheck");
3202-
Builder.CreateCondBr(IVCheck, SuccessorBB, LoopHeaderBB);
3208+
SmallVector<uint32_t> BranchWeights;
3209+
const bool HasBranchWeights =
3210+
!ProfcheckDisableMetadataFixes &&
3211+
extractBranchWeights(*LoopHeaderBB->getTerminator(), BranchWeights);
3212+
3213+
auto *BI = Builder.CreateCondBr(IVCheck, SuccessorBB, LoopHeaderBB);
3214+
if (HasBranchWeights) {
3215+
if (SuccessorBB == LoopHeaderBB->getTerminator()->getSuccessor(1))
3216+
std::swap(BranchWeights[0], BranchWeights[1]);
3217+
// We're not changing the loop profile, so we can reuse the original loop's
3218+
// profile.
3219+
setBranchWeights(*BI, BranchWeights,
3220+
/*IsExpected=*/false);
3221+
}
3222+
32033223
LoopHeaderBB->getTerminator()->eraseFromParent();
32043224

32053225
// Populate the IV PHI.
@@ -3368,10 +3388,10 @@ static bool detectShiftUntilZeroIdiom(Loop *CurLoop, ScalarEvolution *SE,
33683388
/// %start = <...>
33693389
/// %extraoffset = <...>
33703390
/// <...>
3371-
/// br label %for.cond
3391+
/// br label %loop
33723392
///
33733393
/// loop:
3374-
/// %iv = phi i8 [ %start, %entry ], [ %iv.next, %for.cond ]
3394+
/// %iv = phi i8 [ %start, %entry ], [ %iv.next, %loop ]
33753395
/// %nbits = add nsw i8 %iv, %extraoffset
33763396
/// %val.shifted = {{l,a}shr,shl} i8 %val, %nbits
33773397
/// %val.shifted.iszero = icmp eq i8 %val.shifted, 0
@@ -3533,7 +3553,19 @@ bool LoopIdiomRecognize::recognizeShiftUntilZero() {
35333553

35343554
// The loop terminator.
35353555
Builder.SetInsertPoint(LoopHeaderBB->getTerminator());
3536-
Builder.CreateCondBr(CIVCheck, SuccessorBB, LoopHeaderBB);
3556+
SmallVector<uint32_t> BranchWeights;
3557+
const bool HasBranchWeights =
3558+
!ProfcheckDisableMetadataFixes &&
3559+
extractBranchWeights(*LoopHeaderBB->getTerminator(), BranchWeights);
3560+
3561+
auto *BI = Builder.CreateCondBr(CIVCheck, SuccessorBB, LoopHeaderBB);
3562+
if (HasBranchWeights) {
3563+
if (InvertedCond)
3564+
std::swap(BranchWeights[0], BranchWeights[1]);
3565+
// We're not changing the loop profile, so we can reuse the original loop's
3566+
// profile.
3567+
setBranchWeights(*BI, BranchWeights, /*IsExpected=*/false);
3568+
}
35373569
LoopHeaderBB->getTerminator()->eraseFromParent();
35383570

35393571
// Populate the IV PHI.

llvm/lib/Transforms/Vectorize/VPlan.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -304,18 +304,7 @@ Value *VPTransformState::get(const VPValue *Def, bool NeedsScalar) {
304304
}
305305

306306
bool IsSingleScalar = vputils::isSingleScalar(Def);
307-
308307
VPLane LastLane(IsSingleScalar ? 0 : VF.getFixedValue() - 1);
309-
// Check if there is a scalar value for the selected lane.
310-
if (!hasScalarValue(Def, LastLane)) {
311-
// At the moment, VPWidenIntOrFpInductionRecipes, VPScalarIVStepsRecipes and
312-
// VPExpandSCEVRecipes can also be a single scalar.
313-
assert((isa<VPWidenIntOrFpInductionRecipe, VPScalarIVStepsRecipe,
314-
VPExpandSCEVRecipe>(Def->getDefiningRecipe())) &&
315-
"unexpected recipe found to be invariant");
316-
IsSingleScalar = true;
317-
LastLane = 0;
318-
}
319308

320309
// We need to construct the vector value for a single-scalar value by
321310
// broadcasting the scalar to all lanes.

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1725,7 +1725,9 @@ class VPHistogramRecipe : public VPRecipeBase {
17251725
#endif
17261726
};
17271727

1728-
/// A recipe for widening select instructions.
1728+
/// A recipe for widening select instructions. Supports both wide vector and
1729+
/// single-scalar conditions, matching the behavior of LLVM IR's select
1730+
/// instruction.
17291731
struct LLVM_ABI_FOR_TEST VPWidenSelectRecipe : public VPRecipeWithIRFlags,
17301732
public VPIRMetadata {
17311733
VPWidenSelectRecipe(SelectInst &I, ArrayRef<VPValue *> Operands)

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,9 @@ Value *VPInstruction::generate(VPTransformState &State) {
659659
}
660660
case Instruction::Select: {
661661
bool OnlyFirstLaneUsed = vputils::onlyFirstLaneUsed(this);
662-
Value *Cond = State.get(getOperand(0), OnlyFirstLaneUsed);
662+
Value *Cond =
663+
State.get(getOperand(0),
664+
OnlyFirstLaneUsed || vputils::isSingleScalar(getOperand(0)));
663665
Value *Op1 = State.get(getOperand(1), OnlyFirstLaneUsed);
664666
Value *Op2 = State.get(getOperand(2), OnlyFirstLaneUsed);
665667
return Builder.CreateSelect(Cond, Op1, Op2, Name);
@@ -1968,16 +1970,13 @@ void VPWidenSelectRecipe::print(raw_ostream &O, const Twine &Indent,
19681970
getOperand(1)->printAsOperand(O, SlotTracker);
19691971
O << ", ";
19701972
getOperand(2)->printAsOperand(O, SlotTracker);
1971-
O << (isInvariantCond() ? " (condition is loop invariant)" : "");
1973+
O << (vputils::isSingleScalar(getCond()) ? " (condition is single-scalar)"
1974+
: "");
19721975
}
19731976
#endif
19741977

19751978
void VPWidenSelectRecipe::execute(VPTransformState &State) {
1976-
// The condition can be loop invariant but still defined inside the
1977-
// loop. This means that we can't just use the original 'cond' value.
1978-
// We have to take the 'vectorized' value and pick the first lane.
1979-
// Instcombine will make this a no-op.
1980-
Value *Cond = State.get(getCond(), isInvariantCond());
1979+
Value *Cond = State.get(getCond(), vputils::isSingleScalar(getCond()));
19811980

19821981
Value *Op0 = State.get(getOperand(1));
19831982
Value *Op1 = State.get(getOperand(2));

0 commit comments

Comments
 (0)