From 3442700c7cb8171801b1005faa64f7b5bf3d878c Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Mon, 28 Jun 2021 15:57:38 -0400 Subject: [PATCH] [InstCombine][test] add test for potential miscompile with constant expression; NFC (PR50906) --- .../InstCombine/indexed-gep-compares.ll | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test/Transforms/InstCombine/indexed-gep-compares.ll b/test/Transforms/InstCombine/indexed-gep-compares.ll index 2ca2a45d5c3..24410a125d2 100644 --- a/test/Transforms/InstCombine/indexed-gep-compares.ll +++ b/test/Transforms/InstCombine/indexed-gep-compares.ll @@ -249,6 +249,35 @@ bb10: ret i1 %cmp } +; FIXME: +; It is not generally safe to hoist an expression (sdiv) that may trap. + +define i1 @PR50906() { +; CHECK-LABEL: @PR50906( +; CHECK-NEXT: entry: +; CHECK-NEXT: br label [[LOOP:%.*]] +; CHECK: loop: +; CHECK-NEXT: [[CMP:%.*]] = phi i1 [ icmp sgt (i32 sdiv (i32 7, i32 ptrtoint (i1 ()* @PR50906 to i32)), i32 1), [[NEXT:%.*]] ], [ icmp sgt (i32 sdiv (i32 7, i32 ptrtoint (i1 ()* @PR50906 to i32)), i32 0), [[ENTRY:%.*]] ] +; CHECK-NEXT: br label [[NEXT]] +; CHECK: next: +; CHECK-NEXT: br i1 [[CMP]], label [[EXIT:%.*]], label [[LOOP]] +; CHECK: exit: +; CHECK-NEXT: ret i1 [[CMP]] +; +entry: + br label %loop + +loop: + %phi = phi i32 [ 0, %entry ], [ 1, %next ] + br label %next + +next: + %cmp = icmp sgt i32 sdiv (i32 7, i32 ptrtoint (i1 ()* @PR50906 to i32)), %phi + br i1 %cmp, label %exit, label %loop + +exit: + ret i1 %cmp +} declare i32 @__gxx_personality_v0(...)