Skip to content

Commit 662bae8

Browse files
authored
merge main into amd-staging (llvm#1765)
2 parents 2e8a118 + c7812c8 commit 662bae8

File tree

31 files changed

+1541
-457
lines changed

31 files changed

+1541
-457
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,14 +414,16 @@ Improvements to Clang's diagnostics
414414
constructors to initialize their non-modifiable members. The diagnostic is
415415
not new; being controlled via a warning group is what's new. Fixes #GH41104
416416

417+
418+
- Improved Clang's error recovery for invalid function calls.
419+
417420
- Improved bit-field diagnostics to consider the type specified by the
418421
``preferred_type`` attribute. These diagnostics are controlled by the flags
419422
``-Wpreferred-type-bitfield-enum-conversion`` and
420423
``-Wpreferred-type-bitfield-width``. These warnings are on by default as they
421424
they're only triggered if the authors are already making the choice to use
422425
``preferred_type`` attribute.
423426

424-
425427
Improvements to Clang's time-trace
426428
----------------------------------
427429

clang/include/clang/Parse/Parser.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1942,8 +1942,7 @@ class Parser : public CodeCompletionHandler {
19421942
llvm::function_ref<void()> ExpressionStarts =
19431943
llvm::function_ref<void()>(),
19441944
bool FailImmediatelyOnInvalidExpr = false,
1945-
bool EarlyTypoCorrection = false,
1946-
bool *HasTrailingComma = nullptr);
1945+
bool EarlyTypoCorrection = false);
19471946

19481947
/// ParseSimpleExpressionList - A simple comma-separated list of expressions,
19491948
/// used for misc language extensions.

clang/lib/Parse/ParseExpr.cpp

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2218,27 +2218,20 @@ Parser::ParsePostfixExpressionSuffix(ExprResult LHS) {
22182218
CalledSignatureHelp = true;
22192219
return PreferredType;
22202220
};
2221+
bool ExpressionListIsInvalid = false;
22212222
if (OpKind == tok::l_paren || !LHS.isInvalid()) {
22222223
if (Tok.isNot(tok::r_paren)) {
2223-
bool HasTrailingComma = false;
2224-
bool HasError = ParseExpressionList(
2225-
ArgExprs,
2226-
[&] {
2227-
PreferredType.enterFunctionArgument(Tok.getLocation(),
2228-
RunSignatureHelp);
2229-
},
2230-
/*FailImmediatelyOnInvalidExpr*/ false,
2231-
/*EarlyTypoCorrection*/ false, &HasTrailingComma);
2232-
2233-
if (HasError && !HasTrailingComma) {
2224+
if ((ExpressionListIsInvalid = ParseExpressionList(ArgExprs, [&] {
2225+
PreferredType.enterFunctionArgument(Tok.getLocation(),
2226+
RunSignatureHelp);
2227+
}))) {
22342228
(void)Actions.CorrectDelayedTyposInExpr(LHS);
22352229
// If we got an error when parsing expression list, we don't call
22362230
// the CodeCompleteCall handler inside the parser. So call it here
22372231
// to make sure we get overload suggestions even when we are in the
22382232
// middle of a parameter.
22392233
if (PP.isCodeCompletionReached() && !CalledSignatureHelp)
22402234
RunSignatureHelp();
2241-
LHS = ExprError();
22422235
} else if (LHS.isInvalid()) {
22432236
for (auto &E : ArgExprs)
22442237
Actions.CorrectDelayedTyposInExpr(E);
@@ -2249,6 +2242,12 @@ Parser::ParsePostfixExpressionSuffix(ExprResult LHS) {
22492242
// Match the ')'.
22502243
if (LHS.isInvalid()) {
22512244
SkipUntil(tok::r_paren, StopAtSemi);
2245+
} else if (ExpressionListIsInvalid) {
2246+
Expr *Fn = LHS.get();
2247+
ArgExprs.insert(ArgExprs.begin(), Fn);
2248+
LHS = Actions.CreateRecoveryExpr(Fn->getBeginLoc(), Tok.getLocation(),
2249+
ArgExprs);
2250+
SkipUntil(tok::r_paren, StopAtSemi);
22522251
} else if (Tok.isNot(tok::r_paren)) {
22532252
bool HadDelayedTypo = false;
22542253
if (Actions.CorrectDelayedTyposInExpr(LHS).get() != LHS.get())
@@ -3700,8 +3699,7 @@ void Parser::injectEmbedTokens() {
37003699
bool Parser::ParseExpressionList(SmallVectorImpl<Expr *> &Exprs,
37013700
llvm::function_ref<void()> ExpressionStarts,
37023701
bool FailImmediatelyOnInvalidExpr,
3703-
bool EarlyTypoCorrection,
3704-
bool *HasTrailingComma) {
3702+
bool EarlyTypoCorrection) {
37053703
bool SawError = false;
37063704
while (true) {
37073705
if (ExpressionStarts)
@@ -3744,11 +3742,6 @@ bool Parser::ParseExpressionList(SmallVectorImpl<Expr *> &Exprs,
37443742
Token Comma = Tok;
37453743
ConsumeToken();
37463744
checkPotentialAngleBracketDelimiter(Comma);
3747-
3748-
if (Tok.is(tok::r_paren)) {
3749-
if (HasTrailingComma)
3750-
*HasTrailingComma = true;
3751-
}
37523745
}
37533746
if (SawError) {
37543747
// Ensure typos get diagnosed when errors were encountered while parsing the

clang/test/AST/ast-dump-recovery.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,22 @@ void test_invalid_call_1(int s) {
3434

3535
int some_func2(int a, int b);
3636
void test_invalid_call_2() {
37-
// CHECK: -RecoveryExpr {{.*}} 'int' contains-errors
37+
// CHECK: -RecoveryExpr {{.*}} '<dependent type>' contains-errors
3838
// CHECK-NEXT: `-UnresolvedLookupExpr {{.*}} '<overloaded function type>' lvalue (ADL) = 'some_func2'
3939
some_func2(,);
4040

41-
// CHECK: -RecoveryExpr {{.*}} 'int' contains-errors
41+
// CHECK: -RecoveryExpr {{.*}} '<dependent type>' contains-errors
4242
// CHECK-NEXT: `-UnresolvedLookupExpr {{.*}} '<overloaded function type>' lvalue (ADL) = 'some_func2'
4343
some_func2(,,);
4444

45-
// CHECK: `-RecoveryExpr {{.*}} 'int' contains-errors
45+
// CHECK: -RecoveryExpr {{.*}} '<dependent type>' contains-errors
4646
// CHECK-NEXT: |-UnresolvedLookupExpr {{.*}} '<overloaded function type>' lvalue (ADL) = 'some_func2'
4747
// CHECK-NEXT: `-IntegerLiteral {{.*}} 'int' 1
4848
some_func2(1,);
4949

50-
// FIXME: Handle invalid argument with recovery
51-
// CHECK-NOT: `-RecoveryExpr
50+
// CHECK: -RecoveryExpr {{.*}} '<dependent type>' contains-errors
51+
// CHECK-NEXT: |-UnresolvedLookupExpr {{.*}} '<overloaded function type>' lvalue (ADL) = 'some_func2'
52+
// CHECK-NEXT: `-IntegerLiteral {{.*}} 'int' 1
5253
some_func2(,1);
5354
}
5455

clang/test/AST/new-unknown-type.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,15 @@ namespace b {
1717
// CHECK: |-NamespaceDecl 0x{{[^ ]*}} <line:5:1, line:11:1> line:5:11 a
1818
// CHECK-NEXT: | `-FunctionDecl 0x{{[^ ]*}} <line:6:3, line:10:3> line:6:8 computeSomething 'void ()'
1919
// CHECK-NEXT: | `-CompoundStmt 0x{{[^ ]*}} <col:27, line:10:3>
20+
// CHECK-NEXT: | |-RecoveryExpr {{.*}} '<dependent type>' contains-errors
21+
// CHECK-NEXT: | | `-UnresolvedLookupExpr {{.*}} '<overloaded function type>' lvalue (ADL) = 'foo'
22+
// CHECK-NEXT: | |-RecoveryExpr {{.*}} '<dependent type>' contains-errors
23+
// CHECK-NEXT: | | `-UnresolvedLookupExpr {{.*}} '<overloaded function type>' lvalue (ADL) = 'foo'
24+
// CHECK-NEXT: | `-RecoveryExpr {{.*}} '<dependent type>' contains-errors
25+
// CHECK-NEXT: | `-UnresolvedLookupExpr {{.*}} '<overloaded function type>' lvalue (ADL) = 'foo'
2026
// CHECK-NEXT: |-NamespaceDecl 0x{{[^ ]*}} <line:13:1, line:15:1> line:13:11 b
2127
// CHECK-NEXT: | `-CXXRecordDecl 0x{{[^ ]*}} <line:14:3, col:14> col:10 referenced struct Bar definition
2228

2329
static b::Bar bar;
24-
// CHECK: `-VarDecl 0x{{[^ ]*}} <line:23:1, col:15> col:15 bar 'b::Bar' static callinit
30+
// CHECK: `-VarDecl 0x{{[^ ]*}} <line:29:1, col:15> col:15 bar 'b::Bar' static callinit
2531
// CHECK-NEXT: `-CXXConstructExpr 0x{{[^ ]*}} <col:15> 'b::Bar' 'void () noexcept'

clang/test/Parser/cxx-concepts-requires-clause.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ template<typename T> requires 0
119119

120120
template<typename T> requires foo<T>
121121
(int) bar() { };
122-
// expected-error@-1{{expected '(' for function-style cast or type construction}}
122+
// expected-error@-1{{expected '(' for function-style cast or type construction}} \
123+
// expected-error@-2{{parentheses are required around this expression in a requires clause}}
123124

124125
template<typename T>
125126
void bar() requires foo<T>();

compiler-rt/test/profile/AIX/pgo-lto-bcdtor-function-section.test

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,34 @@ int main() { return foo() - 3; }
1515
// RUN: %clang_pgogen -O2 -c -fno-function-sections main.c
1616
//
1717
// RUN: %clang_pgogen -Wl,-bcdtors:all foo.o main.o
18-
// RUN: rm -f default* && %run a.out
18+
// RUN: rm -f default* && %run ./a.out
1919
// RUN: llvm-profdata show --all-functions default* | FileCheck %s -check-prefix=BOTH
2020
//
2121
// RUN: %clang_pgogen -Wl,-bcdtors:mbr foo.o main.o
22-
// RUN: rm -f default* && %run a.out
22+
// RUN: rm -f default* && %run ./a.out
2323
// RUN: llvm-profdata show --all-functions default* | FileCheck %s -check-prefix=BOTH
2424

2525
// RUN: %clang_pgogen -O2 -c -ffunction-sections foo.c
2626
// RUN: %clang_pgogen -O2 -c -ffunction-sections main.c
2727
//
2828
// RUN: %clang_pgogen -Wl,-bcdtors:all foo.o main.o
29-
// RUN: rm -f default* && %run a.out
29+
// RUN: rm -f default* && %run ./a.out
3030
// RUN: llvm-profdata show --all-functions default* | FileCheck %s -check-prefix=BOTH
3131
//
3232
// RUN: %clang_pgogen -Wl,-bcdtors:mbr foo.o main.o
33-
// RUN: rm -f default* && %run a.out
33+
// RUN: rm -f default* && %run ./a.out
3434
// RUN: llvm-profdata show --all-functions default* | FileCheck %s -check-prefix=BOTH
3535

3636
// ## no PGO at compile step, but PGO at link step.
3737
// RUN: %clang -O2 -c foo.c
3838
// RUN: %clang -O2 -c main.c
3939
//
4040
// RUN: %clang_pgogen -Wl,-bcdtors:all foo.o main.o
41-
// RUN: rm -f default* && %run a.out
41+
// RUN: rm -f default* && %run ./a.out
4242
// RUN: llvm-profdata show --all-functions default* | FileCheck %s -check-prefix=NONE
4343
//
4444
// RUN: %clang_pgogen -Wl,-bcdtors:mbr foo.o main.o
45-
// RUN: rm -f default* && %run a.out
45+
// RUN: rm -f default* && %run ./a.out
4646
// RUN: llvm-profdata show --all-functions default* | FileCheck %s -check-prefix=NONE
4747

4848
// # LTO, with and without function-sections, and all permutations of -bcdtors
@@ -51,64 +51,64 @@ int main() { return foo() - 3; }
5151
// RUN: %clang -O2 -c -flto main.c
5252
//
5353
// RUN: %clang_pgogen -flto -fno-function-sections -Wl,-bcdtors:all foo.o main.o
54-
// RUN: rm -f default* && %run a.out
54+
// RUN: rm -f default* && %run ./a.out
5555
// RUN: llvm-profdata show --all-functions default* | FileCheck %s -check-prefix=NONE
5656
//
5757
// RUN: %clang_pgogen -flto -fno-function-sections -Wl,-bcdtors:mbr foo.o main.o
58-
// RUN: rm -f default* && %run a.out
58+
// RUN: rm -f default* && %run ./a.out
5959
// RUN: llvm-profdata show --all-functions default* | FileCheck %s -check-prefix=NONE
6060
//
6161
// RUN: %clang_pgogen -flto -ffunction-sections -Wl,-bcdtors:all foo.o main.o
62-
// RUN: rm -f default* && %run a.out
62+
// RUN: rm -f default* && %run ./a.out
6363
// RUN: llvm-profdata show --all-functions default* | FileCheck %s -check-prefix=NONE
6464
//
6565
// RUN: %clang_pgogen -flto -ffunction-sections -Wl,-bcdtors:mbr foo.o main.o
66-
// RUN: rm -f default* && %run a.out
66+
// RUN: rm -f default* && %run ./a.out
6767
// RUN: llvm-profdata show --all-functions default* | FileCheck %s -check-prefix=NONE
6868

6969
// ## LTO one file, PGO at compile and link
7070
// RUN: %clang -O2 -c -fno-function-sections foo.c
7171
// RUN: %clang_pgogen -O2 -c -flto main.c
7272
// RUN: %clang_pgogen -flto -fno-function-sections -Wl,-bcdtors:all foo.o main.o
73-
// RUN: rm -f default* && %run a.out
73+
// RUN: rm -f default* && %run ./a.out
7474
// RUN: llvm-profdata show --all-functions default* | FileCheck %s -check-prefix=MAIN
7575

7676
// RUN: %clang -O2 -c -flto foo.c
7777
// RUN: %clang_pgogen -O2 -c -fno-function-sections main.c
7878
// RUN: %clang_pgogen -flto -fno-function-sections -Wl,-bcdtors:mbr foo.o main.o
79-
// RUN: rm -f default* && %run a.out
79+
// RUN: rm -f default* && %run ./a.out
8080
// RUN: llvm-profdata show --all-functions default* | FileCheck %s -check-prefix=MAIN
8181

8282
// RUN: %clang -O2 -c -flto foo.c
8383
// RUN: %clang_pgogen -O2 -c -ffunction-sections main.c
8484
// RUN: %clang_pgogen -flto -ffunction-sections -Wl,-bcdtors:all foo.o main.o
85-
// RUN: rm -f default* && %run a.out
85+
// RUN: rm -f default* && %run ./a.out
8686
// RUN: llvm-profdata show --all-functions default* | FileCheck %s -check-prefix=MAIN
8787

8888
// RUN: %clang -O2 -c -ffunction-sections foo.c
8989
// RUN: %clang_pgogen -O2 -c -flto main.c
9090
// RUN: %clang_pgogen -flto -ffunction-sections -Wl,-bcdtors:mbr foo.o main.o
91-
// RUN: rm -f default* && %run a.out
91+
// RUN: rm -f default* && %run ./a.out
9292
// RUN: llvm-profdata show --all-functions default* | FileCheck %s -check-prefix=MAIN
9393

9494
// ## LTO and PGO both files
9595
// RUN: %clang_pgogen -O2 -c -flto foo.c
9696
// RUN: %clang_pgogen -O2 -c -flto main.c
9797
//
9898
// RUN: %clang_pgogen -flto -fno-function-sections -Wl,-bcdtors:all foo.o main.o
99-
// RUN: rm -f default* && %run a.out
99+
// RUN: rm -f default* && %run ./a.out
100100
// RUN: llvm-profdata show --all-functions default* | FileCheck %s -check-prefix=BOTH
101101
//
102102
// RUN: %clang_pgogen -flto -fno-function-sections -Wl,-bcdtors:mbr foo.o main.o
103-
// RUN: rm -f default* && %run a.out
103+
// RUN: rm -f default* && %run ./a.out
104104
// RUN: llvm-profdata show --all-functions default* | FileCheck %s -check-prefix=BOTH
105105
//
106106
// RUN: %clang_pgogen -flto -ffunction-sections -Wl,-bcdtors:all foo.o main.o
107-
// RUN: rm -f default* && %run a.out
107+
// RUN: rm -f default* && %run ./a.out
108108
// RUN: llvm-profdata show --all-functions default* | FileCheck %s -check-prefix=BOTH
109109
//
110110
// RUN: %clang_pgogen -flto -ffunction-sections -Wl,-bcdtors:mbr foo.o main.o
111-
// RUN: rm -f default* && %run a.out
111+
// RUN: rm -f default* && %run ./a.out
112112
// RUN: llvm-profdata show --all-functions default* | FileCheck %s -check-prefix=BOTH
113113

114114
// BOTH-DAG: foo:

flang/include/flang/Optimizer/Dialect/CUF/CUFOps.td

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -254,24 +254,19 @@ def cuf_KernelOp : cuf_Op<"kernel", [AttrSizedOperandSegments,
254254
represented by a 0 constant value.
255255
}];
256256

257-
let arguments = (ins
258-
Variadic<I32>:$grid, // empty means `*`
259-
Variadic<I32>:$block, // empty means `*`
260-
Optional<I32>:$stream,
261-
Variadic<Index>:$lowerbound,
262-
Variadic<Index>:$upperbound,
263-
Variadic<Index>:$step,
264-
OptionalAttr<I64Attr>:$n,
265-
Variadic<AnyType>:$reduceOperands,
266-
OptionalAttr<ArrayAttr>:$reduceAttrs
267-
);
257+
let arguments = (ins Variadic<I32>:$grid, // empty means `*`
258+
Variadic<I32>:$block, // empty means `*`
259+
Optional<fir_ReferenceType>:$stream, Variadic<Index>:$lowerbound,
260+
Variadic<Index>:$upperbound, Variadic<Index>:$step,
261+
OptionalAttr<I64Attr>:$n, Variadic<AnyType>:$reduceOperands,
262+
OptionalAttr<ArrayAttr>:$reduceAttrs);
268263

269264
let regions = (region AnyRegion:$region);
270265

271266
let assemblyFormat = [{
272267
`<` `<` `<` custom<CUFKernelValues>($grid, type($grid)) `,`
273268
custom<CUFKernelValues>($block, type($block))
274-
( `,` `stream` `=` $stream^ )? `>` `>` `>`
269+
( `,` `stream` `=` $stream^ `:` qualified(type($stream)))? `>` `>` `>`
275270
( `reduce` `(` $reduceOperands^ `:` type($reduceOperands) `:` $reduceAttrs `)` )?
276271
custom<CUFKernelLoopControl>($region, $lowerbound, type($lowerbound),
277272
$upperbound, type($upperbound), $step, type($step))

flang/lib/Lower/Bridge.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3097,7 +3097,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
30973097

30983098
llvm::SmallVector<mlir::Value> gridValues;
30993099
llvm::SmallVector<mlir::Value> blockValues;
3100-
mlir::Value streamValue;
3100+
mlir::Value streamAddr;
31013101

31023102
if (launchConfig) {
31033103
const std::list<Fortran::parser::CUFKernelDoConstruct::StarOrExpr> &grid =
@@ -3130,10 +3130,8 @@ class FirConverter : public Fortran::lower::AbstractConverter {
31303130
}
31313131

31323132
if (stream)
3133-
streamValue = builder->createConvert(
3134-
loc, builder->getI32Type(),
3135-
fir::getBase(
3136-
genExprValue(*Fortran::semantics::GetExpr(*stream), stmtCtx)));
3133+
streamAddr = fir::getBase(
3134+
genExprAddr(*Fortran::semantics::GetExpr(*stream), stmtCtx));
31373135
}
31383136

31393137
const auto &outerDoConstruct =
@@ -3267,7 +3265,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
32673265
}
32683266

32693267
auto op = builder->create<cuf::KernelOp>(
3270-
loc, gridValues, blockValues, streamValue, lbs, ubs, steps, n,
3268+
loc, gridValues, blockValues, streamAddr, lbs, ubs, steps, n,
32713269
mlir::ValueRange(reduceOperands), builder->getArrayAttr(reduceAttrs));
32723270
builder->createBlock(&op.getRegion(), op.getRegion().end(), ivTypes,
32733271
ivLocs);

flang/lib/Optimizer/Dialect/CUF/CUFOps.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ llvm::LogicalResult cuf::KernelOp::verify() {
271271
return emitOpError("expect reduce attributes to be ReduceAttr");
272272
}
273273
}
274-
return mlir::success();
274+
return checkStreamType(*this);
275275
}
276276

277277
//===----------------------------------------------------------------------===//

flang/test/Lower/CUDA/cuda-kernel-loop-directive.cuf

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,7 @@ subroutine sub1()
7575
end do
7676
end
7777

78-
! CHECK: %[[STREAM_LOAD:.*]] = fir.load %[[STREAM]]#0 : !fir.ref<i64>
79-
! CHECK: %[[STREAM_I32:.*]] = fir.convert %[[STREAM_LOAD]] : (i64) -> i32
80-
! CHECK: cuf.kernel<<<*, *, stream = %[[STREAM_I32]]>>>
78+
! CHECK: cuf.kernel<<<*, *, stream = %[[STREAM]]#0 : !fir.ref<i64>>>>
8179

8280

8381
! Test lowering with unstructured construct inside.

llvm/lib/Target/NVPTX/NVPTXLowerArgs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ static void handleByValParam(const NVPTXTargetMachine &TM, Argument *Arg) {
536536
const bool IsGridConstant = HasCvtaParam && isParamGridConstant(*Arg);
537537
const DataLayout &DL = Func->getDataLayout();
538538
BasicBlock::iterator FirstInst = Func->getEntryBlock().begin();
539-
Type *StructType = Arg->getParamByValType();
539+
[[maybe_unused]] Type *StructType = Arg->getParamByValType();
540540
assert(StructType && "Missing byval type");
541541

542542
ArgUseChecker AUC(DL, IsGridConstant);

llvm/lib/Target/RISCV/RISCVFrameLowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1272,7 +1272,7 @@ RISCVFrameLowering::getFrameIndexReference(const MachineFunction &MF, int FI,
12721272
// |--------------------------|
12731273
// | VarSize objects |
12741274
// |--------------------------| <-- SP
1275-
if (MFI.getStackID(FI) == TargetStackID::ScalableVector) {
1275+
if (StackID == TargetStackID::ScalableVector) {
12761276
assert(!RI->hasStackRealignment(MF) &&
12771277
"Can't index across variable sized realign");
12781278
// We don't expect any extra RVV alignment padding, as the stack size

llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,9 @@ bool RISCVDAGToDAGISel::trySignedBitfieldExtract(SDNode *Node) {
653653
return false;
654654

655655
const unsigned Msb = ExtSize - 1;
656-
const unsigned Lsb = RightShAmt;
656+
// If the shift-right amount is greater than Msb, it means that extracts
657+
// the X[Msb] bit and sign-extend it.
658+
const unsigned Lsb = RightShAmt > Msb ? Msb : RightShAmt;
657659

658660
SDNode *TH_EXT = BitfieldExtract(N0, Msb, Lsb, DL, VT);
659661
ReplaceNode(Node, TH_EXT);

0 commit comments

Comments
 (0)