[Test] Add test exposing hoisting bug in GuardWidening (NFC)
authorDmitry Makogon <d.makogon@g.nsu.ru>
Tue, 28 Feb 2023 06:30:15 +0000 (13:30 +0700)
committerDmitry Makogon <d.makogon@g.nsu.ru>
Tue, 28 Feb 2023 08:08:32 +0000 (15:08 +0700)
It hoits instruction without making sure its operands are
available at hoisiting point.

llvm/test/Transforms/GuardWidening/widen-cond-with-operands.ll [new file with mode: 0644]

diff --git a/llvm/test/Transforms/GuardWidening/widen-cond-with-operands.ll b/llvm/test/Transforms/GuardWidening/widen-cond-with-operands.ll
new file mode 100644 (file)
index 0000000..398956e
--- /dev/null
@@ -0,0 +1,40 @@
+; RUN: opt -S -passes=guard-widening,verify < %s | FileCheck %s
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128-ni:1-p2:32:8:8:32-ni:2"
+target triple = "x86_64-unknown-linux-gnu"
+
+; REQUIRES: asserts
+; XFAIL: *
+
+; GuardWidening moves 'check' instruction before 'wc1' without its operand ('zero').
+; This is incorrect as 'zero' is not available at that point.
+define void @foo() {
+bb:
+  %wc1 = call i1 @llvm.experimental.widenable.condition()
+  %wc2 = call i1 @llvm.experimental.widenable.condition()
+  %zero = add i32 0, 0
+  %check = icmp ult i32 %zero, 0
+  %c1 = and i1 %check, %wc1
+  %c2 = and i1 %check, %wc2
+  br i1 %c1, label %bb6, label %bb9
+
+bb6:                                              ; preds = %bb
+  br i1 %c2, label %bb7, label %bb8
+
+bb7:                                              ; preds = %bb6
+  ret void
+
+bb8:                                              ; preds = %bb6
+  call void (...) @llvm.experimental.deoptimize.isVoid(i32 0) [ "deopt"() ]
+  ret void
+
+bb9:                                              ; preds = %bb
+  call void (...) @llvm.experimental.deoptimize.isVoid(i32 0) [ "deopt"() ]
+  ret void
+}
+
+declare void @llvm.experimental.deoptimize.isVoid(...)
+
+; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(inaccessiblemem: readwrite)
+declare i1 @llvm.experimental.widenable.condition() #0
+
+attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(inaccessiblemem: readwrite) }