Skip to content

Commit 8543522

Browse files
committed
Merge branch 'main' of https://github.com/llvm/llvm-project into spirv_be_staging_9
2 parents 5b256a5 + b142912 commit 8543522

File tree

9 files changed

+213
-43
lines changed

9 files changed

+213
-43
lines changed

libcxx/include/__locale_dir/support/linux.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,30 @@ inline _LIBCPP_HIDE_FROM_ABI __lconv_t* __localeconv(__locale_t& __loc) {
8383
// Strtonum functions
8484
//
8585
inline _LIBCPP_HIDE_FROM_ABI float __strtof(const char* __nptr, char** __endptr, __locale_t __loc) {
86+
#if !_LIBCPP_HAS_MUSL_LIBC || defined(_GNU_SOURCE)
8687
return ::strtof_l(__nptr, __endptr, __loc);
88+
#else
89+
(void)__loc;
90+
return ::strtof(__nptr, __endptr);
91+
#endif
8792
}
8893

8994
inline _LIBCPP_HIDE_FROM_ABI double __strtod(const char* __nptr, char** __endptr, __locale_t __loc) {
95+
#if !_LIBCPP_HAS_MUSL_LIBC || defined(_GNU_SOURCE)
9096
return ::strtod_l(__nptr, __endptr, __loc);
97+
#else
98+
(void)__loc;
99+
return ::strtod(__nptr, __endptr);
100+
#endif
91101
}
92102

93103
inline _LIBCPP_HIDE_FROM_ABI long double __strtold(const char* __nptr, char** __endptr, __locale_t __loc) {
104+
#if !_LIBCPP_HAS_MUSL_LIBC || defined(_GNU_SOURCE)
94105
return ::strtold_l(__nptr, __endptr, __loc);
106+
#else
107+
(void)__loc;
108+
return ::strtold(__nptr, __endptr);
109+
#endif
95110
}
96111

97112
//

llvm/docs/GettingInvolved.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ what to add to your calendar invite.
209209
- `ics <https://drive.google.com/file/d/1ten-u-4yjOcCoONUtR4_AxsFxRDTUp1b/view?usp=sharing>`__
210210
- `Meeting details/agenda: <https://docs.google.com/document/d/1Glzy2JiWuysbD-HBWGUOkZqT09GJ4_Ljodr0lXD5XfQ/edit>`__
211211
* - `LLVM Qualification Working Group <https://llvm.org/docs/QualGroup.html>`__
212-
- 1st Tuesday/Wednesday of the month
212+
- 1st Tuesday of the month
213213
- `ics <https://calendar.google.com/calendar/ical/c_fe5774fa2769c5085d6b87e8fac272e8940e7d0089bc0e0a58dc3ead7978504b%40group.calendar.google.com/public/basic.ics>`__
214214
`gcal <https://calendar.google.com/calendar/embed?src=c_fe5774fa2769c5085d6b87e8fac272e8940e7d0089bc0e0a58dc3ead7978504b%40group.calendar.google.com&ctz=Asia%2FTokyo>`__
215215
- `Minutes/docs <https://discourse.llvm.org/t/llvm-qualification-wg-sync-ups-meeting-minutes/87148>`__

llvm/docs/QualGroup.rst

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -241,15 +241,8 @@ Agendas, meeting notes, and presentation slides for the sync-ups are shared to e
241241
Upcoming and past meeting agendas, and meeting minutes are published in a dedicated thread
242242
on the LLVM Discourse forum: `Meeting Agendas and Minutes <https://discourse.llvm.org/t/llvm-qualification-wg-sync-ups-meeting-minutes/87148>`_
243243

244-
Slides used to support discussions during sync-up meetings are stored in LLVM's GitHub repository.
245-
246-
Available slides:
247-
248-
* (add future entries here)
249-
* `October 2025 <https://docs.google.com/presentation/d/1ND2SkjgcHvcEbQmMd8ExL-PpRXouP49T-wfy3xf2yRQ/edit?usp=sharing>`_
250-
* `September 2025 <https://docs.google.com/presentation/d/1SZAE-QHfJED6CxJCCtBkPDxcw7XU9ORX54TJyXe1ppc/edit?usp=sharing>`_
251-
* `August 2025 <https://docs.google.com/presentation/d/1K8GWoRm8ZAeyyGvTeV5f-sMOhMr7WHiEk6_Nm5Fk10o/edit?usp=sharing>`_
252-
* `July 2025 <https://docs.google.com/presentation/d/1ktURe9qz5ggbdOQYK-2ISpiC18B-Y_35WvGyAnnxEpw/edit?usp=sharing>`_
244+
Slides used to support discussions during sync-up meetings are stored in a dedicated Google Drive folder: `Link <https://drive.google.com/drive/u/1/folders/1nu3JAanE0gqQDll0S9ofVy4FOFezc6Mm>`_.
245+
Note that the naming convention for these slides is *YYYYMM*\_llvm_qual_wg.
253246

254247
AI Transcription Policy
255248
=======================

llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5886,6 +5886,12 @@ static void collectOffsetOp(Value *V, SmallVectorImpl<OffsetOp> &Offsets,
58865886
Offsets.emplace_back(Instruction::Xor, Inst->getOperand(1));
58875887
Offsets.emplace_back(Instruction::Xor, Inst->getOperand(0));
58885888
break;
5889+
case Instruction::Shl:
5890+
if (Inst->hasNoSignedWrap())
5891+
Offsets.emplace_back(Instruction::AShr, Inst->getOperand(1));
5892+
if (Inst->hasNoUnsignedWrap())
5893+
Offsets.emplace_back(Instruction::LShr, Inst->getOperand(1));
5894+
break;
58895895
case Instruction::Select:
58905896
if (AllowRecursion) {
58915897
collectOffsetOp(Inst->getOperand(1), Offsets, /*AllowRecursion=*/false);
@@ -5942,9 +5948,31 @@ static Instruction *foldICmpEqualityWithOffset(ICmpInst &I,
59425948
collectOffsetOp(Op1, OffsetOps, /*AllowRecursion=*/true);
59435949

59445950
auto ApplyOffsetImpl = [&](Value *V, unsigned BinOpc, Value *RHS) -> Value * {
5951+
switch (BinOpc) {
5952+
// V = shl nsw X, RHS => X = ashr V, RHS
5953+
case Instruction::AShr: {
5954+
const APInt *CV, *CRHS;
5955+
if (!(match(V, m_APInt(CV)) && match(RHS, m_APInt(CRHS)) &&
5956+
CV->ashr(*CRHS).shl(*CRHS) == *CV) &&
5957+
!match(V, m_NSWShl(m_Value(), m_Specific(RHS))))
5958+
return nullptr;
5959+
break;
5960+
}
5961+
// V = shl nuw X, RHS => X = lshr V, RHS
5962+
case Instruction::LShr: {
5963+
const APInt *CV, *CRHS;
5964+
if (!(match(V, m_APInt(CV)) && match(RHS, m_APInt(CRHS)) &&
5965+
CV->lshr(*CRHS).shl(*CRHS) == *CV) &&
5966+
!match(V, m_NUWShl(m_Value(), m_Specific(RHS))))
5967+
return nullptr;
5968+
break;
5969+
}
5970+
default:
5971+
break;
5972+
}
5973+
59455974
Value *Simplified = simplifyBinOp(BinOpc, V, RHS, SQ);
5946-
// Avoid infinite loops by checking if RHS is an identity for the BinOp.
5947-
if (!Simplified || Simplified == V)
5975+
if (!Simplified)
59485976
return nullptr;
59495977
// Reject constant expressions as they don't simplify things.
59505978
if (isa<Constant>(Simplified) && !match(Simplified, m_ImmConstant()))

llvm/test/Transforms/InstCombine/icmp-select.ll

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,3 +835,120 @@ define i1 @discr_eq_constantexpr(ptr %p) {
835835
%cmp = icmp eq i64 %sub, -1
836836
ret i1 %cmp
837837
}
838+
839+
define i1 @shl_nsw_eq_simplify_zero_to_self(i8 %a, i1 %cond) {
840+
; CHECK-LABEL: @shl_nsw_eq_simplify_zero_to_self(
841+
; CHECK-NEXT: [[TMP1:%.*]] = zext i1 [[COND:%.*]] to i8
842+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[A:%.*]], [[TMP1]]
843+
; CHECK-NEXT: ret i1 [[CMP]]
844+
;
845+
%shl = shl nsw i8 %a, 3
846+
%sel = select i1 %cond, i8 8, i8 0
847+
%cmp = icmp eq i8 %shl, %sel
848+
ret i1 %cmp
849+
}
850+
851+
define i1 @shl_nsw_eq(i8 %a, i1 %cond) {
852+
; CHECK-LABEL: @shl_nsw_eq(
853+
; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[COND:%.*]], i8 1, i8 -15
854+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[A:%.*]], [[TMP1]]
855+
; CHECK-NEXT: ret i1 [[CMP]]
856+
;
857+
%shl = shl nsw i8 %a, 3
858+
%sel = select i1 %cond, i8 8, i8 -120
859+
%cmp = icmp eq i8 %shl, %sel
860+
ret i1 %cmp
861+
}
862+
863+
define i1 @shl_nuw_eq(i8 %a, i1 %cond) {
864+
; CHECK-LABEL: @shl_nuw_eq(
865+
; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[COND:%.*]], i8 1, i8 17
866+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[A:%.*]], [[TMP1]]
867+
; CHECK-NEXT: ret i1 [[CMP]]
868+
;
869+
%shl = shl nuw i8 %a, 3
870+
%sel = select i1 %cond, i8 8, i8 -120
871+
%cmp = icmp eq i8 %shl, %sel
872+
ret i1 %cmp
873+
}
874+
875+
define i1 @shl_nsw_failed_to_simplify(i8 %a, i1 %cond) {
876+
; CHECK-LABEL: @shl_nsw_failed_to_simplify(
877+
; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i8 [[A:%.*]], 1
878+
; CHECK-NEXT: [[NOT_COND:%.*]] = xor i1 [[COND:%.*]], true
879+
; CHECK-NEXT: [[CMP:%.*]] = select i1 [[NOT_COND]], i1 [[CMP1]], i1 false
880+
; CHECK-NEXT: ret i1 [[CMP]]
881+
;
882+
%shl = shl nsw i8 %a, 4
883+
%sel = select i1 %cond, i8 8, i8 16
884+
%cmp = icmp eq i8 %shl, %sel
885+
ret i1 %cmp
886+
}
887+
888+
define i1 @shl_nuw_failed_to_simplify(i8 %a, i1 %cond) {
889+
; CHECK-LABEL: @shl_nuw_failed_to_simplify(
890+
; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i8 [[A:%.*]], 4
891+
; CHECK-NEXT: [[NOT_COND:%.*]] = xor i1 [[COND:%.*]], true
892+
; CHECK-NEXT: [[CMP:%.*]] = select i1 [[NOT_COND]], i1 [[CMP1]], i1 false
893+
; CHECK-NEXT: ret i1 [[CMP]]
894+
;
895+
%shl = shl nuw i8 %a, 3
896+
%sel = select i1 %cond, i8 -1, i8 32
897+
%cmp = icmp eq i8 %shl, %sel
898+
ret i1 %cmp
899+
}
900+
901+
define i1 @shl_failed_to_simplify(i8 %a, i1 %cond) {
902+
; CHECK-LABEL: @shl_failed_to_simplify(
903+
; CHECK-NEXT: [[SHL:%.*]] = shl i8 [[A:%.*]], 3
904+
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[COND:%.*]], i8 8, i8 32
905+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[SHL]], [[SEL]]
906+
; CHECK-NEXT: ret i1 [[CMP]]
907+
;
908+
%shl = shl i8 %a, 3
909+
%sel = select i1 %cond, i8 8, i8 32
910+
%cmp = icmp eq i8 %shl, %sel
911+
ret i1 %cmp
912+
}
913+
914+
define i1 @shl_nuw_ne(i8 %a, i8 %b, i8 %c, i1 %cond) {
915+
; CHECK-LABEL: @shl_nuw_ne(
916+
; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[COND:%.*]], i8 [[B:%.*]], i8 4
917+
; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[TMP1]], [[A:%.*]]
918+
; CHECK-NEXT: ret i1 [[CMP]]
919+
;
920+
%shl_a = shl nuw i8 %a, 3
921+
%shl_b = shl nuw i8 %b, 3
922+
%sel = select i1 %cond, i8 %shl_b, i8 32
923+
%cmp = icmp ne i8 %sel, %shl_a
924+
ret i1 %cmp
925+
}
926+
927+
define i1 @shl_const_phi_failed_to_simplify(i64 %indvars, i32 %conv) {
928+
; CHECK-LABEL: @shl_const_phi_failed_to_simplify(
929+
; CHECK-NEXT: entry:
930+
; CHECK-NEXT: [[CMP_SLT:%.*]] = icmp slt i64 [[INDVARS:%.*]], 1
931+
; CHECK-NEXT: br i1 [[CMP_SLT]], label [[END:%.*]], label [[THEN:%.*]]
932+
; CHECK: then:
933+
; CHECK-NEXT: br label [[END]]
934+
; CHECK: end:
935+
; CHECK-NEXT: [[CONST_PHI:%.*]] = phi i32 [ 0, [[THEN]] ], [ 65535, [[ENTRY:%.*]] ]
936+
; CHECK-NEXT: [[SHL_NUW:%.*]] = shl nuw i32 [[CONV:%.*]], 31
937+
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP_SLT]], i32 [[CONST_PHI]], i32 [[SHL_NUW]]
938+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[SEL]], 0
939+
; CHECK-NEXT: ret i1 [[CMP]]
940+
;
941+
entry:
942+
%cmp_slt = icmp slt i64 %indvars, 1
943+
br i1 %cmp_slt, label %end, label %then
944+
945+
then:
946+
br label %end
947+
948+
end:
949+
%const_phi = phi i32 [ 0, %then ], [ 65535, %entry ]
950+
%shl_nuw = shl nuw i32 %conv, 31
951+
%sel = select i1 %cmp_slt, i32 %const_phi, i32 %shl_nuw
952+
%cmp = icmp eq i32 %sel, 0
953+
ret i1 %cmp
954+
}

mlir/include/mlir/Conversion/LLVMCommon/VectorPattern.h

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ LogicalResult vectorOneToOneRewrite(Operation *op, StringRef targetOp,
6060
Attribute propertiesAttr,
6161
const LLVMTypeConverter &typeConverter,
6262
ConversionPatternRewriter &rewriter);
63+
64+
/// Return "true" if the given type is an unsupported floating point type. In
65+
/// case of a vector type, return "true" if the element type is an unsupported
66+
/// floating point type.
67+
bool isUnsupportedFloatingPointType(const TypeConverter &typeConverter,
68+
Type type);
6369
} // namespace detail
6470
} // namespace LLVM
6571

@@ -97,43 +103,25 @@ class VectorConvertToLLVMPattern : public ConvertOpToLLVMPattern<SourceOp> {
97103
using ConvertOpToLLVMPattern<SourceOp>::ConvertOpToLLVMPattern;
98104
using Super = VectorConvertToLLVMPattern<SourceOp, TargetOp>;
99105

100-
/// Return the given type if it's a floating point type. If the given type is
101-
/// a vector type, return its element type if it's a floating point type.
102-
static FloatType getFloatingPointType(Type type) {
103-
if (auto floatType = dyn_cast<FloatType>(type))
104-
return floatType;
105-
if (auto vecType = dyn_cast<VectorType>(type))
106-
return dyn_cast<FloatType>(vecType.getElementType());
107-
return nullptr;
108-
}
109-
110106
LogicalResult
111107
matchAndRewrite(SourceOp op, typename SourceOp::Adaptor adaptor,
112108
ConversionPatternRewriter &rewriter) const override {
113109
static_assert(
114110
std::is_base_of<OpTrait::OneResult<SourceOp>, SourceOp>::value,
115111
"expected single result op");
116112

117-
// The pattern should not apply if a floating-point operand is converted to
118-
// a non-floating-point type. This indicates that the floating point type
119-
// is not supported by the LLVM lowering. (Such types are converted to
120-
// integers.)
121-
auto checkType = [&](Value v) -> LogicalResult {
122-
FloatType floatType = getFloatingPointType(v.getType());
123-
if (!floatType)
124-
return success();
125-
Type convertedType = this->getTypeConverter()->convertType(floatType);
126-
if (!isa_and_nonnull<FloatType>(convertedType))
127-
return rewriter.notifyMatchFailure(op,
128-
"unsupported floating point type");
129-
return success();
130-
};
113+
// Bail on unsupported floating point types. (These are type-converted to
114+
// integer types.)
131115
if (FailOnUnsupportedFP) {
132116
for (Value operand : op->getOperands())
133-
if (failed(checkType(operand)))
134-
return failure();
135-
if (failed(checkType(op->getResult(0))))
136-
return failure();
117+
if (LLVM::detail::isUnsupportedFloatingPointType(
118+
*this->getTypeConverter(), operand.getType()))
119+
return rewriter.notifyMatchFailure(op,
120+
"unsupported floating point type");
121+
if (LLVM::detail::isUnsupportedFloatingPointType(
122+
*this->getTypeConverter(), op->getResult(0).getType()))
123+
return rewriter.notifyMatchFailure(op,
124+
"unsupported floating point type");
137125
}
138126

139127
// Determine attributes for the target op

mlir/lib/Conversion/ArithToLLVM/ArithToLLVM.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,10 @@ CmpIOpLowering::matchAndRewrite(arith::CmpIOp op, OpAdaptor adaptor,
483483
LogicalResult
484484
CmpFOpLowering::matchAndRewrite(arith::CmpFOp op, OpAdaptor adaptor,
485485
ConversionPatternRewriter &rewriter) const {
486+
if (LLVM::detail::isUnsupportedFloatingPointType(*this->getTypeConverter(),
487+
op.getLhs().getType()))
488+
return rewriter.notifyMatchFailure(op, "unsupported floating point type");
489+
486490
Type operandType = adaptor.getLhs().getType();
487491
Type resultType = op.getResult().getType();
488492
LLVM::FastmathFlags fmf =

mlir/lib/Conversion/LLVMCommon/VectorPattern.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,24 @@ LogicalResult LLVM::detail::vectorOneToOneRewrite(
130130
return handleMultidimensionalVectors(op, operands, typeConverter, callback,
131131
rewriter);
132132
}
133+
134+
/// Return the given type if it's a floating point type. If the given type is
135+
/// a vector type, return its element type if it's a floating point type.
136+
static FloatType getFloatingPointType(Type type) {
137+
if (auto floatType = dyn_cast<FloatType>(type))
138+
return floatType;
139+
if (auto vecType = dyn_cast<VectorType>(type))
140+
return dyn_cast<FloatType>(vecType.getElementType());
141+
return nullptr;
142+
}
143+
144+
bool LLVM::detail::isUnsupportedFloatingPointType(
145+
const TypeConverter &typeConverter, Type type) {
146+
FloatType floatType = getFloatingPointType(type);
147+
if (!floatType)
148+
return false;
149+
Type convertedType = typeConverter.convertType(floatType);
150+
if (!convertedType)
151+
return true;
152+
return !isa<FloatType>(convertedType);
153+
}

mlir/test/Conversion/ArithToLLVM/arith-to-llvm.mlir

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -770,12 +770,14 @@ func.func @memref_bitcast(%1: memref<?xi16>) -> memref<?xbf16> {
770770
// CHECK: arith.addf {{.*}} : f4E2M1FN
771771
// CHECK: arith.addf {{.*}} : vector<4xf4E2M1FN>
772772
// CHECK: arith.addf {{.*}} : vector<8x4xf4E2M1FN>
773+
// CHECK: arith.cmpf {{.*}} : f4E2M1FN
773774
// CHECK: llvm.select {{.*}} : i1, i4
774775
func.func @unsupported_fp_type(%arg0: f4E2M1FN, %arg1: vector<4xf4E2M1FN>, %arg2: vector<8x4xf4E2M1FN>, %arg3: f4E2M1FN, %arg4: i1) {
775776
%0 = arith.addf %arg0, %arg0 : f4E2M1FN
776777
%1 = arith.addf %arg1, %arg1 : vector<4xf4E2M1FN>
777778
%2 = arith.addf %arg2, %arg2 : vector<8x4xf4E2M1FN>
778-
%3 = arith.select %arg4, %arg0, %arg3 : f4E2M1FN
779+
%3 = arith.cmpf oeq, %arg0, %arg3 : f4E2M1FN
780+
%4 = arith.select %arg4, %arg0, %arg3 : f4E2M1FN
779781
return
780782
}
781783

@@ -785,9 +787,11 @@ func.func @unsupported_fp_type(%arg0: f4E2M1FN, %arg1: vector<4xf4E2M1FN>, %arg2
785787
// CHECK: llvm.fadd {{.*}} : f32
786788
// CHECK: llvm.fadd {{.*}} : vector<4xf32>
787789
// CHECK-COUNT-4: llvm.fadd {{.*}} : vector<8xf32>
788-
func.func @supported_fp_type(%arg0: f32, %arg1: vector<4xf32>, %arg2: vector<4x8xf32>) -> (f32, vector<4xf32>, vector<4x8xf32>) {
790+
// CHECK: llvm.fcmp {{.*}} : f32
791+
func.func @supported_fp_type(%arg0: f32, %arg1: vector<4xf32>, %arg2: vector<4x8xf32>, %arg3: f32) {
789792
%0 = arith.addf %arg0, %arg0 : f32
790793
%1 = arith.addf %arg1, %arg1 : vector<4xf32>
791794
%2 = arith.addf %arg2, %arg2 : vector<4x8xf32>
792-
return %0, %1, %2 : f32, vector<4xf32>, vector<4x8xf32>
795+
%3 = arith.cmpf oeq, %arg0, %arg3 : f32
796+
return
793797
}

0 commit comments

Comments
 (0)