Skip to content

Commit

Permalink
[Instrumentation][nsan] Add support for Freeze instruction (llvm#100490)
Browse files Browse the repository at this point in the history
Add support for Freeze.

This fixes llvm#98143 .
  • Loading branch information
alexander-shaposhnikov authored Jul 26, 2024
1 parent f4be681 commit 70a9535
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1725,6 +1725,9 @@ Value *NumericalStabilitySanitizer::createShadowValueWithOperandsAvailable(
Map.getShadow(S->getTrueValue()),
Map.getShadow(S->getFalseValue()));

if (auto *Freeze = dyn_cast<FreezeInst>(&Inst))
return Builder.CreateFreeze(Map.getShadow(Freeze->getOperand(0)));

if (auto *Extract = dyn_cast<ExtractElementInst>(&Inst))
return Builder.CreateExtractElement(
Map.getShadow(Extract->getVectorOperand()), Extract->getIndexOperand());
Expand Down
23 changes: 23 additions & 0 deletions llvm/test/Instrumentation/NumericalStabilitySanitizer/basic.ll
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,29 @@ entry:
ret void
}

define void @freeze_vector_insert(<2 x float> %vec, i32 %idx, float %scalar) sanitize_numerical_stability {
; CHECK-LABEL: @freeze_vector_insert(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[TMP0:%.*]] = load i64, ptr @__nsan_shadow_args_tag, align 8
; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i64 [[TMP0]], ptrtoint (ptr @freeze_vector_insert to i64)
; CHECK-NEXT: [[TMP2:%.*]] = load <2 x double>, ptr @__nsan_shadow_args_ptr, align 1
; CHECK-NEXT: [[TMP3:%.*]] = fpext <2 x float> [[VEC:%.*]] to <2 x double>
; CHECK-NEXT: [[TMP4:%.*]] = select i1 [[TMP1]], <2 x double> [[TMP2]], <2 x double> [[TMP3]]
; CHECK-NEXT: [[TMP5:%.*]] = load double, ptr getelementptr ([16384 x i8], ptr @__nsan_shadow_args_ptr, i64 0, i64 16), align 1
; CHECK-NEXT: [[TMP6:%.*]] = fpext float [[SCALAR:%.*]] to double
; CHECK-NEXT: [[TMP7:%.*]] = select i1 [[TMP1]], double [[TMP5]], double [[TMP6]]
; CHECK-NEXT: store i64 0, ptr @__nsan_shadow_args_tag, align 8
; CHECK-NEXT: [[TMP8:%.*]] = insertelement <2 x float> [[VEC]], float [[SCALAR]], i32 [[IDX:%.*]]
; CHECK-NEXT: [[TMP9:%.*]] = insertelement <2 x double> [[TMP4]], double [[TMP7]], i32 [[IDX]]
; CHECK-NEXT: [[FROZEN:%.*]] = freeze <2 x float> [[TMP8]]
; CHECK-NEXT: [[TMP10:%.*]] = freeze <2 x double> [[TMP9]]
; CHECK-NEXT: ret void
;
entry:
%1 = insertelement <2 x float> %vec, float %scalar, i32 %idx
%frozen = freeze <2 x float> %1
ret void
}

define void @vector_shuffle(<2 x float> %0) sanitize_numerical_stability {
; CHECK-LABEL: @vector_shuffle(
Expand Down

0 comments on commit 70a9535

Please sign in to comment.