diff --git a/lib/Transforms/Instrumentation/MemorySanitizer.cpp b/lib/Transforms/Instrumentation/MemorySanitizer.cpp index d547adc86e1..f2e1ab7513c 100644 --- a/lib/Transforms/Instrumentation/MemorySanitizer.cpp +++ b/lib/Transforms/Instrumentation/MemorySanitizer.cpp @@ -2082,13 +2082,20 @@ struct MemorySanitizerVisitor : public InstVisitor { // Origins are always i32, so any vector conditions must be flattened. // FIXME: consider tracking vector origins for app vectors? Value *Cond = I.getCondition(); + Value *CondShadow = getShadow(Cond); if (Cond->getType()->isVectorTy()) { - Value *ConvertedShadow = convertToShadowTyNoVec(Cond, IRB); - Cond = IRB.CreateICmpNE(ConvertedShadow, - getCleanShadow(ConvertedShadow), "_mso_select"); + Type *FlatTy = getShadowTyNoVec(Cond->getType()); + Cond = IRB.CreateICmpNE(IRB.CreateBitCast(Cond, FlatTy), + ConstantInt::getNullValue(FlatTy)); + CondShadow = IRB.CreateICmpNE(IRB.CreateBitCast(CondShadow, FlatTy), + ConstantInt::getNullValue(FlatTy)); } - setOrigin(&I, IRB.CreateSelect(Cond, - getOrigin(I.getTrueValue()), getOrigin(I.getFalseValue()))); + // a = select b, c, d + // Oa = Sb ? Ob : (b ? Oc : Od) + setOrigin(&I, IRB.CreateSelect( + CondShadow, getOrigin(I.getCondition()), + IRB.CreateSelect(Cond, getOrigin(I.getTrueValue()), + getOrigin(I.getFalseValue())))); } } diff --git a/test/Instrumentation/MemorySanitizer/msan_basic.ll b/test/Instrumentation/MemorySanitizer/msan_basic.ll index fceb3f00753..ec756161ef4 100644 --- a/test/Instrumentation/MemorySanitizer/msan_basic.ll +++ b/test/Instrumentation/MemorySanitizer/msan_basic.ll @@ -255,6 +255,7 @@ entry: ; CHECK-NEXT: select ; CHECK-ORIGINS: select ; CHECK-ORIGINS: select +; CHECK: select ; CHECK: ret i32 @@ -274,6 +275,9 @@ entry: ; CHECK-NEXT: or <8 x i16> ; CHECK-ORIGINS: bitcast <8 x i1> {{.*}} to i8 ; CHECK-ORIGINS: icmp ne i8 {{.*}}, 0 +; CHECK-ORIGINS: bitcast <8 x i1> {{.*}} to i8 +; CHECK-ORIGINS: icmp ne i8 {{.*}}, 0 +; CHECK-ORIGINS: select i1 ; CHECK-ORIGINS: select i1 ; CHECK: select <8 x i1> ; CHECK: ret <8 x i16> @@ -295,6 +299,8 @@ entry: ; CHECK: sext i1 {{.*}} to i128 ; CHECK: bitcast i128 {{.*}} to <8 x i16> ; CHECK: or <8 x i16> +; CHECK-ORIGINS: select i1 +; CHECK-ORIGINS: select i1 ; CHECK: select i1 ; CHECK: ret <8 x i16> @@ -309,6 +315,7 @@ entry: ; CHECK: select i1 {{.*}}, { i64, i64 } ; CHECK-NEXT: select i1 {{.*}}, { i64, i64 } { i64 -1, i64 -1 }, { i64, i64 } ; CHECK-ORIGINS: select i1 +; CHECK-ORIGINS: select i1 ; CHECK-NEXT: select i1 {{.*}}, { i64, i64 } ; CHECK: ret { i64, i64 }