Skip to content

Commit c176ed1

Browse files
SC llvm teamSC llvm team
SC llvm team
authored and
SC llvm team
committed
Merged main:caf0897c9c7f6f2a142af06bff8680a23d1d4bf5 into amd-gfx:bd53c0b2e9b9
Local branch amd-gfx bd53c0b Merged main:21627236363d629f6a5b820f45a6071371e4b8db into amd-gfx:842efb6db236 Remote branch main caf0897 [SPIR-V] Fix deprecation warnings after llvm#102608 (llvm#109447)
2 parents bd53c0b + caf0897 commit c176ed1

File tree

53 files changed

+1104
-778
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1104
-778
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
============================
2+
External Clang-Tidy Examples
3+
============================
4+
5+
Introduction
6+
============
7+
8+
This page provides examples of what people have done with :program:`clang-tidy` that
9+
might serve as useful guides (or starting points) to develop your own checks.
10+
They may be helpful for necessary things such as how to write the `CMakeLists.txt`
11+
for an out-of-tree plugin of :program:`clang-tidy` checks.
12+
13+
If you know of (or wrote!) a tool or project using :program:`clang-tidy`, please share it
14+
on `the Discourse forums (Clang Frontend category)
15+
<https://discourse.llvm.org/c/clang/6>`_ for wider visibility and open a
16+
pull-request on `LLVM Github`_ to have it added here. Since the primary purpose of
17+
this page is to provide examples that can help developers, the listed projects should
18+
have code available.
19+
20+
As :program:`clang-tidy` is using, for example, the AST Matchers and diagnostics of Clang,
21+
`External Clang Examples`_ may also be useful to look at for such examples.
22+
23+
.. _LLVM Github: https://github.com/llvm/llvm-project
24+
.. _External Clang Examples: https://clang.llvm.org/docs/ExternalClangExamples.html
25+
26+
List of projects and tools
27+
==========================
28+
29+
`<https://github.com/coveooss/clang-tidy-plugin-examples>`_
30+
"This folder contains :program:`clang-tidy` plugins."

clang-tools-extra/docs/clang-tidy/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ See also:
1212
The list of clang-tidy checks <checks/list>
1313
Clang-tidy IDE/Editor Integrations <Integrations>
1414
Getting Involved <Contributing>
15+
External Clang-Tidy Examples <ExternalClang-TidyExamples>
1516

1617
:program:`clang-tidy` is a clang-based C++ "linter" tool. Its purpose is to
1718
provide an extensible framework for diagnosing and fixing typical programming

clang/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ if (CLANG_BOLT AND NOT LLVM_BUILD_INSTRUMENTED)
917917
-data ${BOLT_FDATA}
918918
-reorder-blocks=ext-tsp -reorder-functions=cdsort -split-functions
919919
-split-all-cold -split-eh -dyno-stats -use-gnu-stack
920-
-split-strategy=cdsplit -update-debug-sections
920+
-update-debug-sections
921921
${BOLT_NO_LBR}
922922
COMMENT "Optimizing Clang with BOLT"
923923
USES_TERMINAL

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13649,7 +13649,7 @@ Value *CodeGenFunction::EmitBPFBuiltinExpr(unsigned BuiltinID,
1364913649
else
1365013650
InitValStr = std::to_string(InitVal.getZExtValue());
1365113651
std::string EnumStr = Enumerator->getNameAsString() + ":" + InitValStr;
13652-
Value *EnumStrVal = Builder.CreateGlobalStringPtr(EnumStr);
13652+
Value *EnumStrVal = Builder.CreateGlobalString(EnumStr);
1365313653

1365413654
ConstantInt *Flag = cast<ConstantInt>(EmitScalarExpr(E->getArg(1)));
1365513655
Value *FlagValue = ConstantInt::get(Int64Ty, Flag->getSExtValue());

clang/lib/CodeGen/CGExprScalar.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1807,7 +1807,7 @@ ScalarExprEmitter::VisitSYCLUniqueStableNameExpr(SYCLUniqueStableNameExpr *E) {
18071807
ASTContext &Context = CGF.getContext();
18081808
unsigned AddrSpace =
18091809
Context.getTargetAddressSpace(CGF.CGM.GetGlobalConstantAddressSpace());
1810-
llvm::Constant *GlobalConstStr = Builder.CreateGlobalStringPtr(
1810+
llvm::Constant *GlobalConstStr = Builder.CreateGlobalString(
18111811
E->ComputeName(Context), "__usn_str", AddrSpace);
18121812

18131813
llvm::Type *ExprTy = ConvertType(E->getType());

clang/lib/CodeGen/CGStmt.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,7 @@ void CodeGenFunction::EmitIfStmt(const IfStmt &S) {
815815
// C99 6.8.4.1: The first substatement is executed if the expression compares
816816
// unequal to 0. The condition must be a scalar type.
817817
LexicalScope ConditionScope(*this, S.getCond()->getSourceRange());
818+
ApplyDebugLocation DL(*this, S.getCond());
818819

819820
if (S.getInit())
820821
EmitStmt(S.getInit());

clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,10 @@ static std::optional<std::string> printReferrer(const MemRegion *Referrer) {
337337
// warn_bind_ref_member_to_parameter or
338338
// warn_init_ptr_member_to_parameter_addr
339339
return std::nullopt;
340+
} else if (isa<AllocaRegion>(Referrer)) {
341+
// Skip alloca() regions, they indicate advanced memory management
342+
// and higher likelihood of CSA false positives.
343+
return std::nullopt;
340344
} else {
341345
assert(false && "Unexpected referrer region type.");
342346
return std::nullopt;

clang/test/Analysis/stack-addr-ps.cpp

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
1-
// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify %s -Wno-undefined-bool-conversion
1+
// RUN: %clang_analyze_cc1 \
2+
// RUN: -analyzer-checker=core,debug.ExprInspection \
3+
// RUN: -verify %s \
4+
// RUN: -Wno-undefined-bool-conversion
5+
// RUN: %clang_analyze_cc1 \
6+
// RUN: -analyzer-checker=core,debug.ExprInspection,unix.Malloc \
7+
// RUN: -verify %s \
8+
// RUN: -Wno-undefined-bool-conversion
9+
// unix.Malloc is necessary to model __builtin_alloca,
10+
// which could trigger an "unexpected region" bug in StackAddrEscapeChecker.
211

312
typedef __INTPTR_TYPE__ intptr_t;
413

514
template <typename T>
615
void clang_analyzer_dump(T x);
716

17+
using size_t = decltype(sizeof(int));
18+
void * malloc(size_t size);
19+
void free(void*);
20+
821
const int& g() {
922
int s;
1023
return s; // expected-warning{{Address of stack memory associated with local variable 's' returned}} expected-warning{{reference to stack memory associated with local variable 's' returned}}
@@ -846,3 +859,21 @@ void top(char **p) {
846859
foo(); // no-warning FIXME: p binding is reclaimed before the function end
847860
}
848861
} // namespace early_reclaim_dead_limitation
862+
863+
namespace alloca_region_pointer {
864+
void callee(char **pptr) {
865+
char local;
866+
*pptr = &local;
867+
} // no crash
868+
869+
void top_alloca_no_crash_fn() {
870+
char **pptr = (char**)__builtin_alloca(sizeof(char*));
871+
callee(pptr);
872+
}
873+
874+
void top_malloc_no_crash_fn() {
875+
char **pptr = (char**)malloc(sizeof(char*));
876+
callee(pptr);
877+
free(pptr);
878+
}
879+
} // namespace alloca_region_pointer
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// RUN: %clang_cc1 -debug-info-kind=limited -gno-column-info -triple=x86_64-pc-linux -emit-llvm %s -o - | FileCheck %s
2+
3+
// The important thing is that the compare and the conditional branch have
4+
// locs with the same scope (the lexical block for the 'if'). By turning off
5+
// column info, they end up with the same !dbg record, which halves the number
6+
// of checks to verify the scope.
7+
8+
int c = 2;
9+
10+
int f() {
11+
#line 100
12+
if (int a = 5; a > c)
13+
return 1;
14+
return 0;
15+
}
16+
// CHECK-LABEL: define {{.*}} @_Z1fv()
17+
// CHECK: = icmp {{.*}} !dbg [[F_CMP:![0-9]+]]
18+
// CHECK-NEXT: br i1 {{.*}} !dbg [[F_CMP]]
19+
20+
int g() {
21+
#line 200
22+
if (int a = f())
23+
return 2;
24+
return 3;
25+
}
26+
// CHECK-LABEL: define {{.*}} @_Z1gv()
27+
// CHECK: = icmp {{.*}} !dbg [[G_CMP:![0-9]+]]
28+
// CHECK-NEXT: br i1 {{.*}} !dbg [[G_CMP]]
29+
30+
int h() {
31+
#line 300
32+
if (c > 3)
33+
return 4;
34+
return 5;
35+
}
36+
// CHECK-LABEL: define {{.*}} @_Z1hv()
37+
// CHECK: = icmp {{.*}} !dbg [[H_CMP:![0-9]+]]
38+
// CHECK-NEXT: br i1 {{.*}} !dbg [[H_CMP]]
39+
40+
// CHECK-DAG: [[F_CMP]] = !DILocation(line: 100, scope: [[F_SCOPE:![0-9]+]]
41+
// CHECK-DAG: [[F_SCOPE]] = distinct !DILexicalBlock({{.*}} line: 100)
42+
// CHECK-DAG: [[G_CMP]] = !DILocation(line: 200, scope: [[G_SCOPE:![0-9]+]]
43+
// CHECK-DAG: [[G_SCOPE]] = distinct !DILexicalBlock({{.*}} line: 200)
44+
// CHECK-DAG: [[H_CMP]] = !DILocation(line: 300, scope: [[H_SCOPE:![0-9]+]]
45+
// CHECK-DAG: [[H_SCOPE]] = distinct !DILexicalBlock({{.*}} line: 300)

compiler-rt/test/profile/Posix/instrprof-dlopen-norpath.test

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
RUN: rm -rf %t && split-file %s %t && cd %t
2-
RUN: %clang_pgogen -fPIC foo.c -c -Xclang -fprofile-instrument-path="default_foo_%m.profraw"
3-
RUN: %clang_pgogen -fPIC foo2.c -c -Xclang -fprofile-instrument-path="default_foo2_%m.profraw"
4-
RUN: %clang_pgogen -shared foo.o -o shr_foo.o %if target={{.*aix.*}} %{ -bcdtors:mbr %}
5-
RUN: %clang_pgogen -shared foo2.o -o shr_foo2.o
2+
RUN: %clang_pgogen -fprofile-update=atomic -fPIC foo.c -c -Xclang -fprofile-instrument-path="default_foo_%m.profraw"
3+
RUN: %clang_pgogen -fprofile-update=atomic -fPIC foo2.c -c -Xclang -fprofile-instrument-path="default_foo2_%m.profraw"
4+
RUN: %clang_pgogen -fprofile-update=atomic -shared foo.o -o shr_foo.o %if target={{.*aix.*}} %{ -bcdtors:mbr %}
5+
RUN: %clang_pgogen -fprofile-update=atomic -shared foo2.o -o shr_foo2.o
66

77
RUN: %clang_pgogen common.c -c
88

llvm/include/llvm-c/Core.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4526,6 +4526,9 @@ LLVMValueRef LLVMBuildStructGEP2(LLVMBuilderRef B, LLVMTypeRef Ty,
45264526
const char *Name);
45274527
LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
45284528
const char *Name);
4529+
/**
4530+
* Deprecated: Use LLVMBuildGlobalString instead, which has identical behavior.
4531+
*/
45294532
LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
45304533
const char *Name);
45314534
LLVMBool LLVMGetVolatile(LLVMValueRef MemoryAccessInst);

llvm/include/llvm/Config/llvm-config.h.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
/* Indicate that this is LLVM compiled from the amd-gfx branch. */
1818
#define LLVM_HAVE_BRANCH_AMD_GFX
19-
#define LLVM_MAIN_REVISION 512734
19+
#define LLVM_MAIN_REVISION 512751
2020

2121
/* Define if LLVM_ENABLE_DUMP is enabled */
2222
#cmakedefine LLVM_ENABLE_DUMP

llvm/include/llvm/IR/IRBuilder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2015,6 +2015,7 @@ class IRBuilderBase {
20152015
///
20162016
/// If no module is given via \p M, it is take from the insertion point basic
20172017
/// block.
2018+
LLVM_DEPRECATED("Use CreateGlobalString instead", "CreateGlobalString")
20182019
Constant *CreateGlobalStringPtr(StringRef Str, const Twine &Name = "",
20192020
unsigned AddressSpace = 0,
20202021
Module *M = nullptr, bool AddNull = true) {

llvm/lib/Analysis/LoopAccessAnalysis.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2449,13 +2449,20 @@ bool LoopAccessInfo::analyzeLoop(AAResults *AA, const LoopInfo *LI,
24492449
continue;
24502450

24512451
// If this is a load, save it. If this instruction can read from memory
2452-
// but is not a load, then we quit. Notice that we don't handle function
2453-
// calls that read or write.
2452+
// but is not a load, we only allow it if it's a call to a function with a
2453+
// vector mapping and no pointer arguments.
24542454
if (I.mayReadFromMemory()) {
2455-
// If the function has an explicit vectorized counterpart, we can safely
2456-
// assume that it can be vectorized.
2455+
auto hasPointerArgs = [](CallBase *CB) {
2456+
return any_of(CB->args(), [](Value const *Arg) {
2457+
return Arg->getType()->isPointerTy();
2458+
});
2459+
};
2460+
2461+
// If the function has an explicit vectorized counterpart, and does not
2462+
// take output/input pointers, we can safely assume that it can be
2463+
// vectorized.
24572464
if (Call && !Call->isNoBuiltin() && Call->getCalledFunction() &&
2458-
!VFDatabase::getMappings(*Call).empty())
2465+
!hasPointerArgs(Call) && !VFDatabase::getMappings(*Call).empty())
24592466
continue;
24602467

24612468
auto *Ld = dyn_cast<LoadInst>(&I);

llvm/lib/CodeGen/StackProtector.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ BasicBlock *CreateFailBB(Function *F, const Triple &Trip) {
705705
StackChkFail = M->getOrInsertFunction("__stack_smash_handler",
706706
Type::getVoidTy(Context),
707707
PointerType::getUnqual(Context));
708-
Args.push_back(B.CreateGlobalStringPtr(F->getName(), "SSH"));
708+
Args.push_back(B.CreateGlobalString(F->getName(), "SSH"));
709709
} else {
710710
StackChkFail =
711711
M->getOrInsertFunction("__stack_chk_fail", Type::getVoidTy(Context));

llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -886,8 +886,8 @@ Constant *OpenMPIRBuilder::getOrCreateSrcLocStr(StringRef LocStr,
886886
GV.getInitializer() == Initializer)
887887
return SrcLocStr = ConstantExpr::getPointerCast(&GV, Int8Ptr);
888888

889-
SrcLocStr = Builder.CreateGlobalStringPtr(LocStr, /* Name */ "",
890-
/* AddressSpace */ 0, &M);
889+
SrcLocStr = Builder.CreateGlobalString(LocStr, /* Name */ "",
890+
/* AddressSpace */ 0, &M);
891891
}
892892
return SrcLocStr;
893893
}

llvm/lib/IR/Core.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4060,7 +4060,7 @@ LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
40604060

40614061
LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
40624062
const char *Name) {
4063-
return wrap(unwrap(B)->CreateGlobalStringPtr(Str, Name));
4063+
return wrap(unwrap(B)->CreateGlobalString(Str, Name));
40644064
}
40654065

40664066
LLVMBool LLVMGetVolatile(LLVMValueRef MemAccessInst) {

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -635,8 +635,17 @@ InstructionCost RISCVTTIImpl::getScalarizationOverhead(
635635
InstructionCost Cost = BaseT::getScalarizationOverhead(
636636
Ty, DemandedElts, Insert, Extract, CostKind);
637637
std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost(Ty);
638-
if (Insert && !Extract && LT.first.isValid() && LT.second.isVector() &&
639-
Ty->getScalarSizeInBits() != 1) {
638+
if (Insert && !Extract && LT.first.isValid() && LT.second.isVector()) {
639+
if (Ty->getScalarSizeInBits() == 1) {
640+
auto *WideVecTy = cast<VectorType>(Ty->getWithNewBitWidth(8));
641+
// Note: Implicit scalar anyextend is assumed to be free since the i1
642+
// must be stored in a GPR.
643+
return getScalarizationOverhead(WideVecTy, DemandedElts, Insert, Extract,
644+
CostKind) +
645+
getCastInstrCost(Instruction::Trunc, Ty, WideVecTy,
646+
TTI::CastContextHint::None, CostKind, nullptr);
647+
}
648+
640649
assert(LT.second.isFixedLengthVector());
641650
MVT ContainerVT = TLI->getContainerForFixedLengthVector(LT.second);
642651
if (isM1OrSmaller(ContainerVT)) {

llvm/lib/Target/SPIRV/SPIRVRegularizer.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ void SPIRVRegularizer::runLowerConstExpr(Function &F) {
127127
ReplList.push_back(Inst);
128128
Repl = InsertElementInst::Create(
129129
(Repl ? Repl : PoisonValue::get(Vec->getType())), V,
130-
ConstantInt::get(Type::getInt32Ty(Ctx), Idx++), "", InsPoint);
130+
ConstantInt::get(Type::getInt32Ty(Ctx), Idx++), "",
131+
InsPoint->getIterator());
131132
}
132133
WorkList.splice(WorkList.begin(), ReplList);
133134
return Repl;
@@ -234,11 +235,12 @@ void SPIRVRegularizer::visitCallScalToVec(CallInst *CI, StringRef MangledName,
234235
// %call = OpExtInst %v2uint %1 s_min %14 %11
235236
auto ConstInt = ConstantInt::get(IntegerType::get(CI->getContext(), 32), 0);
236237
PoisonValue *PVal = PoisonValue::get(Arg0Ty);
237-
Instruction *Inst =
238-
InsertElementInst::Create(PVal, CI->getOperand(1), ConstInt, "", CI);
238+
Instruction *Inst = InsertElementInst::Create(
239+
PVal, CI->getOperand(1), ConstInt, "", CI->getIterator());
239240
ElementCount VecElemCount = cast<VectorType>(Arg0Ty)->getElementCount();
240241
Constant *ConstVec = ConstantVector::getSplat(VecElemCount, ConstInt);
241-
Value *NewVec = new ShuffleVectorInst(Inst, PVal, ConstVec, "", CI);
242+
Value *NewVec =
243+
new ShuffleVectorInst(Inst, PVal, ConstVec, "", CI->getIterator());
242244
CI->setOperand(1, NewVec);
243245
CI->replaceUsesOfWith(OldF, NewF);
244246
CI->mutateFunctionType(NewF->getFunctionType());

llvm/lib/Target/SPIRV/SPIRVStripConvergentIntrinsics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class SPIRVStripConvergentIntrinsics : public FunctionPass {
6262
return;
6363

6464
auto *NewCall = CallBase::removeOperandBundle(
65-
CI, LLVMContext::OB_convergencectrl, CI);
65+
CI, LLVMContext::OB_convergencectrl, CI->getIterator());
6666
NewCall->copyMetadata(*CI);
6767
CI->replaceAllUsesWith(NewCall);
6868
ToRemove.insert(CI);

llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,13 @@ void StrNCmpInliner::inlineCompare(Value *LHS, StringRef RHS, uint64_t N,
10521052
bool Swapped) {
10531053
auto &Ctx = CI->getContext();
10541054
IRBuilder<> B(Ctx);
1055+
// We want these instructions to be recognized as inlined instructions for the
1056+
// compare call, but we don't have a source location for the definition of
1057+
// that function, since we're generating that code now. Because the generated
1058+
// code is a viable point for a memory access error, we make the pragmatic
1059+
// choice here to directly use CI's location so that we have useful
1060+
// attribution for the generated code.
1061+
B.SetCurrentDebugLocation(CI->getDebugLoc());
10551062

10561063
BasicBlock *BBCI = CI->getParent();
10571064
BasicBlock *BBTail =

llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3551,9 +3551,7 @@ Instruction *InstCombinerImpl::foldSelectToCmp(SelectInst &SI) {
35513551
Pred = ICmpInst::getSwappedPredicate(Pred);
35523552
std::swap(LHS, RHS);
35533553
}
3554-
3555-
Intrinsic::ID IID =
3556-
ICmpInst::isSigned(Pred) ? Intrinsic::scmp : Intrinsic::ucmp;
3554+
bool IsSigned = ICmpInst::isSigned(Pred);
35573555

35583556
bool Replace = false;
35593557
ICmpInst::Predicate ExtendedCmpPredicate;
@@ -3575,6 +3573,32 @@ Instruction *InstCombinerImpl::foldSelectToCmp(SelectInst &SI) {
35753573
ICmpInst::getSwappedPredicate(ExtendedCmpPredicate) == Pred))
35763574
Replace = true;
35773575

3576+
// (x == y) ? 0 : (x > y ? 1 : -1)
3577+
ICmpInst::Predicate FalseBranchSelectPredicate;
3578+
const APInt *InnerTV, *InnerFV;
3579+
if (Pred == ICmpInst::ICMP_EQ && match(TV, m_Zero()) &&
3580+
match(FV, m_Select(m_c_ICmp(FalseBranchSelectPredicate, m_Specific(LHS),
3581+
m_Specific(RHS)),
3582+
m_APInt(InnerTV), m_APInt(InnerFV)))) {
3583+
if (!ICmpInst::isGT(FalseBranchSelectPredicate)) {
3584+
FalseBranchSelectPredicate =
3585+
ICmpInst::getSwappedPredicate(FalseBranchSelectPredicate);
3586+
std::swap(LHS, RHS);
3587+
}
3588+
3589+
if (!InnerTV->isOne()) {
3590+
std::swap(InnerTV, InnerFV);
3591+
std::swap(LHS, RHS);
3592+
}
3593+
3594+
if (ICmpInst::isGT(FalseBranchSelectPredicate) && InnerTV->isOne() &&
3595+
InnerFV->isAllOnes()) {
3596+
IsSigned = ICmpInst::isSigned(FalseBranchSelectPredicate);
3597+
Replace = true;
3598+
}
3599+
}
3600+
3601+
Intrinsic::ID IID = IsSigned ? Intrinsic::scmp : Intrinsic::ucmp;
35783602
if (Replace)
35793603
return replaceInstUsesWith(
35803604
SI, Builder.CreateIntrinsic(SI.getType(), IID, {LHS, RHS}));

0 commit comments

Comments
 (0)