Skip to content

Commit 22255e0

Browse files
SC llvm teamSC llvm team
SC llvm team
authored and
SC llvm team
committed
Merged main:f95710c76519c611868c16f92586b6d0baedad54 into amd-gfx:b97a8ed014a8
Local branch amd-gfx b97a8ed Merged main:a83f8e0314fcdda162e54cbba1c9dcf230dff093 into amd-gfx:bc01ccc911bf Remote branch main f95710c [flang] Fixed compiler build on glibc 2.17 systems after 3149c93. (llvm#84873)
2 parents b97a8ed + f95710c commit 22255e0

File tree

11 files changed

+2676
-15
lines changed

11 files changed

+2676
-15
lines changed

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 77 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2959,6 +2959,8 @@ bool ByteCodeExprGen<Emitter>::VisitCXXThisExpr(const CXXThisExpr *E) {
29592959
template <class Emitter>
29602960
bool ByteCodeExprGen<Emitter>::VisitUnaryOperator(const UnaryOperator *E) {
29612961
const Expr *SubExpr = E->getSubExpr();
2962+
if (SubExpr->getType()->isAnyComplexType())
2963+
return this->VisitComplexUnaryOperator(E);
29622964
std::optional<PrimType> T = classify(SubExpr->getType());
29632965

29642966
switch (E->getOpcode()) {
@@ -3109,16 +3111,81 @@ bool ByteCodeExprGen<Emitter>::VisitUnaryOperator(const UnaryOperator *E) {
31093111
return false;
31103112
return DiscardResult ? this->emitPop(*T, E) : this->emitComp(*T, E);
31113113
case UO_Real: // __real x
3112-
if (T)
3113-
return this->delegate(SubExpr);
3114-
return this->emitComplexReal(SubExpr);
3114+
assert(T);
3115+
return this->delegate(SubExpr);
31153116
case UO_Imag: { // __imag x
3116-
if (T) {
3117-
if (!this->discard(SubExpr))
3117+
assert(T);
3118+
if (!this->discard(SubExpr))
3119+
return false;
3120+
return this->visitZeroInitializer(*T, SubExpr->getType(), SubExpr);
3121+
}
3122+
case UO_Extension:
3123+
return this->delegate(SubExpr);
3124+
case UO_Coawait:
3125+
assert(false && "Unhandled opcode");
3126+
}
3127+
3128+
return false;
3129+
}
3130+
3131+
template <class Emitter>
3132+
bool ByteCodeExprGen<Emitter>::VisitComplexUnaryOperator(
3133+
const UnaryOperator *E) {
3134+
const Expr *SubExpr = E->getSubExpr();
3135+
assert(SubExpr->getType()->isAnyComplexType());
3136+
3137+
if (DiscardResult)
3138+
return this->discard(SubExpr);
3139+
3140+
std::optional<PrimType> ResT = classify(E);
3141+
3142+
// Prepare storage for result.
3143+
if (!ResT && !Initializing) {
3144+
std::optional<unsigned> LocalIndex =
3145+
allocateLocal(SubExpr, /*IsExtended=*/false);
3146+
if (!LocalIndex)
3147+
return false;
3148+
if (!this->emitGetPtrLocal(*LocalIndex, E))
3149+
return false;
3150+
}
3151+
3152+
// The offset of the temporary, if we created one.
3153+
unsigned SubExprOffset = ~0u;
3154+
auto createTemp = [=, &SubExprOffset]() -> bool {
3155+
SubExprOffset = this->allocateLocalPrimitive(SubExpr, PT_Ptr, true, false);
3156+
if (!this->visit(SubExpr))
3157+
return false;
3158+
return this->emitSetLocal(PT_Ptr, SubExprOffset, E);
3159+
};
3160+
3161+
PrimType ElemT = classifyComplexElementType(SubExpr->getType());
3162+
auto getElem = [=](unsigned Offset, unsigned Index) -> bool {
3163+
if (!this->emitGetLocal(PT_Ptr, Offset, E))
3164+
return false;
3165+
return this->emitArrayElemPop(ElemT, Index, E);
3166+
};
3167+
3168+
switch (E->getOpcode()) {
3169+
case UO_Minus:
3170+
if (!createTemp())
3171+
return false;
3172+
for (unsigned I = 0; I != 2; ++I) {
3173+
if (!getElem(SubExprOffset, I))
3174+
return false;
3175+
if (!this->emitNeg(ElemT, E))
3176+
return false;
3177+
if (!this->emitInitElem(ElemT, I, E))
31183178
return false;
3119-
return this->visitZeroInitializer(*T, SubExpr->getType(), SubExpr);
31203179
}
3180+
break;
3181+
3182+
case UO_AddrOf:
3183+
return this->delegate(SubExpr);
31213184

3185+
case UO_Real:
3186+
return this->emitComplexReal(SubExpr);
3187+
3188+
case UO_Imag:
31223189
if (!this->visit(SubExpr))
31233190
return false;
31243191

@@ -3131,14 +3198,12 @@ bool ByteCodeExprGen<Emitter>::VisitUnaryOperator(const UnaryOperator *E) {
31313198
// Since our _Complex implementation does not map to a primitive type,
31323199
// we sometimes have to do the lvalue-to-rvalue conversion here manually.
31333200
return this->emitArrayElemPop(classifyPrim(E->getType()), 1, E);
3134-
}
3135-
case UO_Extension:
3136-
return this->delegate(SubExpr);
3137-
case UO_Coawait:
3138-
assert(false && "Unhandled opcode");
3201+
3202+
default:
3203+
return this->emitInvalid(E);
31393204
}
31403205

3141-
return false;
3206+
return true;
31423207
}
31433208

31443209
template <class Emitter>

clang/lib/AST/Interp/ByteCodeExprGen.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class ByteCodeExprGen : public ConstStmtVisitor<ByteCodeExprGen<Emitter>, bool>,
7575
bool VisitGNUNullExpr(const GNUNullExpr *E);
7676
bool VisitCXXThisExpr(const CXXThisExpr *E);
7777
bool VisitUnaryOperator(const UnaryOperator *E);
78+
bool VisitComplexUnaryOperator(const UnaryOperator *E);
7879
bool VisitDeclRefExpr(const DeclRefExpr *E);
7980
bool VisitImplicitValueInitExpr(const ImplicitValueInitExpr *E);
8081
bool VisitSubstNonTypeTemplateParmExpr(const SubstNonTypeTemplateParmExpr *E);

flang/include/flang/Evaluate/integer.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
#include <string>
2828
#include <type_traits>
2929

30+
// Some environments, viz. glibc 2.17, allow the macro HUGE
31+
// to leak out of <math.h>.
32+
#undef HUGE
33+
3034
namespace Fortran::evaluate::value {
3135

3236
// Implements an integer as an assembly of smaller host integer parts

flang/include/flang/Evaluate/real.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
#include <limits>
1919
#include <string>
2020

21+
// Some environments, viz. glibc 2.17, allow the macro HUGE
22+
// to leak out of <math.h>.
23+
#undef HUGE
24+
2125
namespace llvm {
2226
class raw_ostream;
2327
}

flang/lib/Evaluate/fold-implementation.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@
3939
#include <type_traits>
4040
#include <variant>
4141

42+
// Some environments, viz. glibc 2.17, allow the macro HUGE
43+
// to leak out of <math.h>.
44+
#undef HUGE
45+
4246
namespace Fortran::evaluate {
4347

4448
// Utilities

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 492361
19+
#define LLVM_MAIN_REVISION 492365
2020

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

llvm/lib/Target/X86/X86.td

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,8 +1237,6 @@ def ProcessorFeatures {
12371237
// Gracemont
12381238
list<SubtargetFeature> GRTTuning = [TuningMacroFusion,
12391239
TuningSlow3OpsLEA,
1240-
TuningSlowDivide32,
1241-
TuningSlowDivide64,
12421240
TuningFastScalarFSQRT,
12431241
TuningFastVectorFSQRT,
12441242
TuningFast15ByteNOP,

llvm/test/CodeGen/X86/bypass-slow-division-tune.ll

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
; RUN: llc -mtriple=x86_64-unknown-linux-gnu -mcpu=x86-64 < %s | FileCheck -check-prefixes=CHECK,REST,X64 %s
55
; RUN: llc -mtriple=x86_64-unknown-linux-gnu -mcpu=silvermont < %s | FileCheck -check-prefixes=CHECK,REST,SLM %s
66
; RUN: llc -mtriple=x86_64-unknown-linux-gnu -mcpu=skylake < %s | FileCheck -check-prefixes=CHECK,REST,SKL %s
7+
; RUN: llc -mtriple=x86_64-unknown-linux-gnu -mcpu=goldmont < %s | FileCheck -check-prefixes=CHECK,REST,GMT %s
8+
; RUN: llc -mtriple=x86_64-unknown-linux-gnu -mcpu=gracemont < %s | FileCheck -check-prefixes=CHECK,REST,GMT %s
79
; RUN: llc -profile-summary-huge-working-set-size-threshold=1 -mtriple=x86_64-unknown-linux-gnu -mcpu=skylake < %s | FileCheck -check-prefixes=HUGEWS %s
810

911
; Verify that div32 is bypassed only for Atoms.
@@ -117,6 +119,13 @@ define i64 @div64(i64 %a, i64 %b) {
117119
; SKL-NEXT: # kill: def $eax killed $eax def $rax
118120
; SKL-NEXT: retq
119121
;
122+
; GMT-LABEL: div64:
123+
; GMT: # %bb.0: # %entry
124+
; GMT-NEXT: movq %rdi, %rax
125+
; GMT-NEXT: cqto
126+
; GMT-NEXT: idivq %rsi
127+
; GMT-NEXT: retq
128+
;
120129
; HUGEWS-LABEL: div64:
121130
; HUGEWS: # %bb.0: # %entry
122131
; HUGEWS-NEXT: movq %rdi, %rax
@@ -240,6 +249,13 @@ define i64 @div64_hugews(i64 %a, i64 %b) {
240249
; SKL-NEXT: # kill: def $eax killed $eax def $rax
241250
; SKL-NEXT: retq
242251
;
252+
; GMT-LABEL: div64_hugews:
253+
; GMT: # %bb.0:
254+
; GMT-NEXT: movq %rdi, %rax
255+
; GMT-NEXT: cqto
256+
; GMT-NEXT: idivq %rsi
257+
; GMT-NEXT: retq
258+
;
243259
; HUGEWS-LABEL: div64_hugews:
244260
; HUGEWS: # %bb.0:
245261
; HUGEWS-NEXT: movq %rdi, %rax

0 commit comments

Comments
 (0)