aeubanks updated this revision to Diff 475017.
aeubanks added a comment.
I somehow missed the previous comments
rebased on top of fixing UB in tests changes
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D133036/new/
https://reviews.llvm.org/D133036
Files:
llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
llvm/test/Transforms/InstCombine/call-undef.ll
llvm/test/Transforms/InstCombine/out-of-bounds-indexes.ll
Index: llvm/test/Transforms/InstCombine/out-of-bounds-indexes.ll
===================================================================
--- llvm/test/Transforms/InstCombine/out-of-bounds-indexes.ll
+++ llvm/test/Transforms/InstCombine/out-of-bounds-indexes.ll
@@ -6,7 +6,7 @@
; CHECK-LABEL: @test_out_of_bounds(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[AND1:%.*]] = and i32 [[A:%.*]], 3
-; CHECK-NEXT: tail call void @llvm.assume(i1 poison)
+; CHECK-NEXT: store i1 true, ptr poison, align 1
; CHECK-NEXT: ret i32 [[AND1]]
;
entry:
@@ -20,7 +20,7 @@
define i128 @test_non64bit(i128 %a) {
; CHECK-LABEL: @test_non64bit(
; CHECK-NEXT: [[AND1:%.*]] = and i128 [[A:%.*]], 3
-; CHECK-NEXT: tail call void @llvm.assume(i1 poison)
+; CHECK-NEXT: store i1 true, ptr poison, align 1
; CHECK-NEXT: ret i128 [[AND1]]
;
%and1 = and i128 %a, 3
Index: llvm/test/Transforms/InstCombine/call-undef.ll
===================================================================
--- llvm/test/Transforms/InstCombine/call-undef.ll
+++ llvm/test/Transforms/InstCombine/call-undef.ll
@@ -1,5 +1,6 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -passes=instcombine -S | FileCheck %s
+; RUN: opt < %s -passes=instcombine -S -instcombine-disable-optimize-passing-undef-ub | FileCheck %s --check-prefix=DISABLE
declare void @c(i32 noundef)
declare void @d(ptr dereferenceable(1))
@@ -8,8 +9,12 @@
define void @test1() {
; CHECK-LABEL: @test1(
-; CHECK-NEXT: call void @c(i32 undef)
+; CHECK-NEXT: store i1 true, ptr poison, align 1
; CHECK-NEXT: ret void
+;
+; DISABLE-LABEL: @test1(
+; DISABLE-NEXT: call void @c(i32 undef)
+; DISABLE-NEXT: ret void
;
call void @c(i32 undef)
ret void
@@ -17,8 +22,12 @@
define void @test2() {
; CHECK-LABEL: @test2(
-; CHECK-NEXT: call void @c(i32 poison)
+; CHECK-NEXT: store i1 true, ptr poison, align 1
; CHECK-NEXT: ret void
+;
+; DISABLE-LABEL: @test2(
+; DISABLE-NEXT: call void @c(i32 poison)
+; DISABLE-NEXT: ret void
;
call void @c(i32 poison)
ret void
@@ -26,8 +35,12 @@
define void @test3() {
; CHECK-LABEL: @test3(
-; CHECK-NEXT: call void @e(i32 noundef undef)
+; CHECK-NEXT: store i1 true, ptr poison, align 1
; CHECK-NEXT: ret void
+;
+; DISABLE-LABEL: @test3(
+; DISABLE-NEXT: call void @e(i32 noundef undef)
+; DISABLE-NEXT: ret void
;
call void @e(i32 noundef undef)
ret void
@@ -35,8 +48,12 @@
define void @test4() {
; CHECK-LABEL: @test4(
-; CHECK-NEXT: call void @e(i32 noundef poison)
+; CHECK-NEXT: store i1 true, ptr poison, align 1
; CHECK-NEXT: ret void
+;
+; DISABLE-LABEL: @test4(
+; DISABLE-NEXT: call void @e(i32 noundef poison)
+; DISABLE-NEXT: ret void
;
call void @e(i32 noundef poison)
ret void
@@ -44,8 +61,12 @@
define void @test5() {
; CHECK-LABEL: @test5(
-; CHECK-NEXT: call void @d(ptr undef)
+; CHECK-NEXT: store i1 true, ptr poison, align 1
; CHECK-NEXT: ret void
+;
+; DISABLE-LABEL: @test5(
+; DISABLE-NEXT: call void @d(ptr undef)
+; DISABLE-NEXT: ret void
;
call void @d(ptr undef)
ret void
@@ -53,8 +74,12 @@
define void @test6() {
; CHECK-LABEL: @test6(
-; CHECK-NEXT: call void @d(ptr poison)
+; CHECK-NEXT: store i1 true, ptr poison, align 1
; CHECK-NEXT: ret void
+;
+; DISABLE-LABEL: @test6(
+; DISABLE-NEXT: call void @d(ptr poison)
+; DISABLE-NEXT: ret void
;
call void @d(ptr poison)
ret void
@@ -62,8 +87,12 @@
define void @test7() {
; CHECK-LABEL: @test7(
-; CHECK-NEXT: call void @f(ptr dereferenceable(1) undef)
+; CHECK-NEXT: store i1 true, ptr poison, align 1
; CHECK-NEXT: ret void
+;
+; DISABLE-LABEL: @test7(
+; DISABLE-NEXT: call void @f(ptr dereferenceable(1) undef)
+; DISABLE-NEXT: ret void
;
call void @f(ptr dereferenceable(1) undef)
ret void
@@ -71,17 +100,38 @@
define void @test8() {
; CHECK-LABEL: @test8(
-; CHECK-NEXT: call void @f(ptr dereferenceable(1) poison)
+; CHECK-NEXT: store i1 true, ptr poison, align 1
; CHECK-NEXT: ret void
+;
+; DISABLE-LABEL: @test8(
+; DISABLE-NEXT: call void @f(ptr dereferenceable(1) poison)
+; DISABLE-NEXT: ret void
;
call void @f(ptr dereferenceable(1) poison)
ret void
}
+define void @test9() sanitize_memory {
+; CHECK-LABEL: @test9(
+; CHECK-NEXT: call void @c(i32 undef)
+; CHECK-NEXT: ret void
+;
+; DISABLE-LABEL: @test9(
+; DISABLE-NEXT: call void @c(i32 undef)
+; DISABLE-NEXT: ret void
+;
+ call void @c(i32 undef)
+ ret void
+}
+
define void @test_mismatched_call() {
; CHECK-LABEL: @test_mismatched_call(
; CHECK-NEXT: call void @e(i8 poison)
; CHECK-NEXT: ret void
+;
+; DISABLE-LABEL: @test_mismatched_call(
+; DISABLE-NEXT: call void @e(i8 poison)
+; DISABLE-NEXT: ret void
;
call void @e(i8 poison)
ret void
Index: llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -88,6 +88,12 @@
cl::desc("How wide an instruction window to bypass looking for "
"another guard"));
+// TODO: remove this flag after LLVM ToT users have resolved issues around this.
+static cl::opt<bool> DisableOptimizePassingUndefUB(
+ "instcombine-disable-optimize-passing-undef-ub", cl::init(false),
+ cl::desc("Disable optimizing away undefined behavior around passing undef "
+ "to noundef params"));
+
namespace llvm {
/// enable preservation of attributes in assume like:
/// call void @llvm.assume(i1 true) [ "nonnull"(i32* %PTR) ]
@@ -3016,6 +3022,19 @@
return nullptr;
}
+static bool callPassesUndefToPassingUndefUBParam(CallBase &Call) {
+ if (DisableOptimizePassingUndefUB)
+ return false;
+ // Optimizing this hurts msan's usefulness.
+ if (Call.getParent()->getParent()->hasFnAttribute(Attribute::SanitizeMemory))
+ return false;
+ for (unsigned I = 0; I < Call.arg_size(); ++I) {
+ if (isa<UndefValue>(Call.getArgOperand(I)) && Call.isPassingUndefUB(I))
+ return true;
+ }
+ return false;
+}
+
bool InstCombinerImpl::annotateAnyAllocSite(CallBase &Call,
const TargetLibraryInfo *TLI) {
// Note: We only handle cases which can't be driven from generic attributes
@@ -3142,9 +3161,11 @@
// Calling a null function pointer is undefined if a null address isn't
// dereferenceable.
+ // Passing undef/poison to any parameter where doing so is UB is undefined (of
+ // course).
if ((isa<ConstantPointerNull>(Callee) &&
!NullPointerIsDefined(Call.getFunction())) ||
- isa<UndefValue>(Callee)) {
+ isa<UndefValue>(Callee) || callPassesUndefToPassingUndefUBParam(Call)) {
// If Call does not return void then replaceInstUsesWith poison.
// This allows ValueHandlers and custom metadata to adjust itself.
if (!Call.getType()->isVoidTy())
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits