diff --git a/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp b/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp index e2493c5aa83d64..035cbdf595a8cd 100644 --- a/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp +++ b/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp @@ -441,7 +441,7 @@ static Constant *getMemSetPatternValue(Value *V, const DataLayout *DL) { // array. We could theoretically do a store to an alloca or something, but // that doesn't seem worthwhile. Constant *C = dyn_cast(V); - if (!C) + if (!C || isa(C)) return nullptr; // Only handle simple values that are a power of two bytes in size. diff --git a/llvm/test/Transforms/LoopIdiom/basic.ll b/llvm/test/Transforms/LoopIdiom/basic.ll index d114abcffb5f79..43c4f62e501527 100644 --- a/llvm/test/Transforms/LoopIdiom/basic.ll +++ b/llvm/test/Transforms/LoopIdiom/basic.ll @@ -1583,4 +1583,36 @@ for.end: ; preds = %for.body, %entry ret void } +%class.CMSPULog = type { %struct._opaque_pthread_mutex_t, ptr, i32, i32, i32, i8, i8, i8, [512 x i32] } +%struct._opaque_pthread_mutex_t = type { i64, [56 x i8] } + +define noalias ptr @_ZN8CMSPULog9beginImplEja(ptr nocapture writeonly %0) local_unnamed_addr #0 { +; CHECK-LABEL: @_ZN8CMSPULog9beginImplEja( +; CHECK-NEXT: br label [[TMP2:%.*]] +; CHECK: 2: +; CHECK-NEXT: [[TMP3:%.*]] = phi i32 [ 0, [[TMP1:%.*]] ], [ [[TMP4:%.*]], [[TMP2]] ] +; CHECK-NEXT: [[TMP4]] = add nuw nsw i32 [[TMP3]], 1 +; CHECK-NEXT: [[TMP5:%.*]] = zext i32 [[TMP3]] to i64 +; CHECK-NEXT: [[TMP6:%.*]] = getelementptr [[CLASS_CMSPULOG:%.*]], ptr [[TMP0:%.*]], i64 0, i32 8, i64 [[TMP5]] +; CHECK-NEXT: store i32 trunc (i64 and (i64 ptrtoint (ptr @G to i64), i64 16777215) to i32), ptr [[TMP6]], align 4 +; CHECK-NEXT: [[TMP7:%.*]] = icmp ult i32 [[TMP3]], 511 +; CHECK-NEXT: br i1 [[TMP7]], label [[TMP2]], label [[TMP8:%.*]] +; CHECK: 8: +; CHECK-NEXT: ret ptr null +; + br label %2 + +2: ; preds = %1, %2 + %3 = phi i32 [ 0, %1 ], [ %4, %2 ] + %4 = add nuw nsw i32 %3, 1 + %5 = zext i32 %3 to i64 + %6 = getelementptr %class.CMSPULog, ptr %0, i64 0, i32 8, i64 %5 + store i32 trunc (i64 and (i64 ptrtoint (ptr @G to i64), i64 16777215) to i32), ptr %6, align 4 + %7 = icmp ult i32 %3, 511 + br i1 %7, label %2, label %8 + +8: ; preds = %2 + ret ptr null +} + ; Validate that "memset_pattern" has the proper attributes.