Skip to content

Commit 7eb398e

Browse files
committed
Refactor to NotV1 / NotV2
1 parent 86a1df3 commit 7eb398e

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2512,24 +2512,25 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
25122512
// S = S | (V1 & V2)
25132513
Value *S1 = getShadow(&I, 0);
25142514
Value *S2 = getShadow(&I, 1);
2515-
// Gotcha: V1 and V2 are NOT'ed here
2516-
Value *V1 = IRB.CreateNot(I.getOperand(0));
2517-
Value *V2 = IRB.CreateNot(I.getOperand(1));
2515+
Value *V1 = I.getOperand(0);
2516+
Value *V2 = I.getOperand(1);
25182517
if (V1->getType() != S1->getType()) {
25192518
V1 = IRB.CreateIntCast(V1, S1->getType(), false);
25202519
V2 = IRB.CreateIntCast(V2, S2->getType(), false);
25212520
}
2521+
2522+
Value *NotV1 = IRB.CreateNot(V1);
2523+
Value *NotV2 = IRB.CreateNot(V2);
2524+
25222525
Value *S1S2 = IRB.CreateAnd(S1, S2);
2523-
Value *V1S2 = IRB.CreateAnd(V1, S2);
2524-
Value *S1V2 = IRB.CreateAnd(S1, V2);
2526+
Value *S2NotV1 = IRB.CreateAnd(NotV1, S2);
2527+
Value *S1NotV2 = IRB.CreateAnd(S1, NotV2);
2528+
2529+
Value *S = IRB.CreateOr({S1S2, S2NotV1, S1NotV2});
25252530

2526-
Value *S = IRB.CreateOr({S1S2, V1S2, S1V2});
25272531
if (ClPreciseDisjointOr && cast<PossiblyDisjointInst>(&I)->isDisjoint()) {
2528-
// "V1" and "V2" were NOT'ed above
2529-
V1 = IRB.CreateIntCast(I.getOperand(0), S1->getType(), false);
2530-
V2 = IRB.CreateIntCast(I.getOperand(1), S2->getType(), false);
25312532
Value *V1V2 = IRB.CreateAnd(V1, V2);
2532-
S = IRB.CreateOr({S, V1V2});
2533+
S = IRB.CreateOr(S, V1V2, "_ms_disjoint");
25332534
}
25342535

25352536
setShadow(&I, S);

llvm/test/Instrumentation/MemorySanitizer/or.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ define i8 @test_disjoint_or(i8 %a, i8 %b) sanitize_memory {
4646
; CHECK-IMPRECISE-NEXT: store i8 [[TMP11]], ptr @__msan_retval_tls, align 8
4747
;
4848
; CHECK-PRECISE: [[TMP10:%.*]] = and i8 [[A]], [[B]]
49-
; CHECK-PRECISE-NEXT: [[TMP11:%.*]] = or i8 [[TMP9]], [[TMP10]]
49+
; CHECK-PRECISE-NEXT: [[TMP12:%.*]] = or i8 [[TMP11]], [[TMP10]]
5050
; CHECK-PRECISE-NEXT: [[C:%.*]] = or disjoint i8 [[A]], [[B]]
51-
; CHECK-PRECISE-NEXT: store i8 [[TMP11]], ptr @__msan_retval_tls, align 8
51+
; CHECK-PRECISE-NEXT: store i8 [[TMP12]], ptr @__msan_retval_tls, align 8
5252
;
5353
; CHECK-NEXT: ret i8 [[C]]
5454
;

0 commit comments

Comments
 (0)