Skip to content

[SimplifyCFG] Bail out on vector GEPs in passingValueIsAlwaysUndefined #142526

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 4, 2025

Conversation

dtcxzyw
Copy link
Member

@dtcxzyw dtcxzyw commented Jun 3, 2025

Closes #142522.

@dtcxzyw dtcxzyw requested review from asb and nikic June 3, 2025 03:15
@llvmbot
Copy link
Member

llvmbot commented Jun 3, 2025

@llvm/pr-subscribers-llvm-transforms

Author: Yingwei Zheng (dtcxzyw)

Changes

Closes #142522.


Full diff: https://github.com/llvm/llvm-project/pull/142526.diff

2 Files Affected:

  • (modified) llvm/lib/Transforms/Utils/SimplifyCFG.cpp (+5)
  • (modified) llvm/test/Transforms/SimplifyCFG/UnreachableEliminate.ll (+20)
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index b7299e01b0c5f..898ff3d1f8f12 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -8109,6 +8109,7 @@ bool SimplifyCFGOpt::simplifyCondBranch(BranchInst *BI, IRBuilder<> &Builder) {
 
 /// Check if passing a value to an instruction will cause undefined behavior.
 static bool passingValueIsAlwaysUndefined(Value *V, Instruction *I, bool PtrValueMayBeModified) {
+  assert(V->getType() == I->getType() && "Mismatched types");
   Constant *C = dyn_cast<Constant>(V);
   if (!C)
     return false;
@@ -8177,6 +8178,10 @@ static bool passingValueIsAlwaysUndefined(Value *V, Instruction *I, bool PtrValu
              NullPointerIsDefined(GEP->getFunction(),
                                   GEP->getPointerAddressSpace())))
           PtrValueMayBeModified = true;
+        // The type of GEP may differ from the type of base pointer.
+        if (V->getType() != GEP->getType())
+          V = ConstantVector::getSplat(
+              cast<VectorType>(GEP->getType())->getElementCount(), C);
         return passingValueIsAlwaysUndefined(V, GEP, PtrValueMayBeModified);
       }
 
diff --git a/llvm/test/Transforms/SimplifyCFG/UnreachableEliminate.ll b/llvm/test/Transforms/SimplifyCFG/UnreachableEliminate.ll
index 2da5d18b63f49..5b439a23c3585 100644
--- a/llvm/test/Transforms/SimplifyCFG/UnreachableEliminate.ll
+++ b/llvm/test/Transforms/SimplifyCFG/UnreachableEliminate.ll
@@ -244,6 +244,7 @@ declare ptr @fn_nonnull_arg(ptr nonnull %p)
 declare ptr @fn_noundef_arg(ptr noundef %p)
 declare ptr @fn_ptr_arg(ptr)
 declare ptr @fn_ptr_arg_nounwind_willreturn(ptr) nounwind willreturn
+declare void @fn_arg_vec(<2 x ptr>)
 
 define void @test9(i1 %X, ptr %Y) {
 ; CHECK-LABEL: @test9(
@@ -917,6 +918,25 @@ bb5:                                              ; preds = %bb3, %bb
   ret i32 %i7
 }
 
+define void @test9_gep_splat(i1 %X, ptr %Y) {
+; CHECK-LABEL: @test9_gep_splat(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[SPEC_SELECT:%.*]] = select i1 [[X:%.*]], ptr null, ptr [[Y:%.*]]
+; CHECK-NEXT:    [[GEP:%.*]] = getelementptr i8, ptr [[SPEC_SELECT]], <2 x i64> zeroinitializer
+; CHECK-NEXT:    call void @fn_arg_vec(<2 x ptr> [[GEP]])
+; CHECK-NEXT:    ret void
+;
+entry:
+  br i1 %X, label %if, label %else
+if:
+  br label %else
+else:
+  %phi = phi ptr [ %Y, %entry ], [ null, %if ]
+  %gep = getelementptr i8, ptr %phi, <2 x i64> zeroinitializer
+  call void @fn_arg_vec(<2 x ptr> %gep)
+  ret void
+}
+
 declare void @side.effect()
 declare i8 @get.i8()
 

@dtcxzyw dtcxzyw changed the title [SimplifyCFG] Handle vector GEP in passingValueIsAlwaysUndefined [SimplifyCFG] Bail out on vector GEPs in passingValueIsAlwaysUndefined Jun 3, 2025
@dtcxzyw dtcxzyw merged commit 7e1fa09 into llvm:main Jun 4, 2025
11 checks passed
@dtcxzyw dtcxzyw deleted the fix-142522 branch June 4, 2025 04:37
@llvm-ci
Copy link
Collaborator

llvm-ci commented Jun 4, 2025

LLVM Buildbot has detected a new failure on builder openmp-s390x-linux running on systemz-1 while building llvm at step 6 "test-openmp".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/88/builds/12412

Here is the relevant piece of the build log for the reference
Step 6 (test-openmp) failure: test (failure)
******************** TEST 'libomp :: tasking/issue-94260-2.c' FAILED ********************
Exit Code: -11

Command Output (stdout):
--
# RUN: at line 1
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/./bin/clang -fopenmp   -I /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -I /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test -L /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/src  -fno-omit-frame-pointer -mbackchain -I /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test/ompt /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test/tasking/issue-94260-2.c -o /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp -lm -latomic && /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
# executed command: /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/./bin/clang -fopenmp -I /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -I /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test -L /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -fno-omit-frame-pointer -mbackchain -I /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test/ompt /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test/tasking/issue-94260-2.c -o /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp -lm -latomic
# executed command: /home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
# note: command had no output on stdout or stderr
# error: command failed with exit status: -11

--

********************


@llvm-ci
Copy link
Collaborator

llvm-ci commented Jun 4, 2025

LLVM Buildbot has detected a new failure on builder sanitizer-aarch64-linux-bootstrap-asan running on sanitizer-buildbot7 while building llvm at step 2 "annotate".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/24/builds/9128

Here is the relevant piece of the build log for the reference
Step 2 (annotate) failure: 'python ../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py' (failure)
...
llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520: note: using lld-link: /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build2_asan/bin/lld-link
llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520: note: using ld64.lld: /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build2_asan/bin/ld64.lld
llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520: note: using wasm-ld: /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build2_asan/bin/wasm-ld
llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520: note: using ld.lld: /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build2_asan/bin/ld.lld
llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520: note: using lld-link: /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build2_asan/bin/lld-link
llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520: note: using ld64.lld: /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build2_asan/bin/ld64.lld
llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520: note: using wasm-ld: /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build2_asan/bin/wasm-ld
llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/main.py:73: note: The test suite configuration requested an individual test timeout of 0 seconds but a timeout of 900 seconds was requested on the command line. Forcing timeout to be 900 seconds.
-- Testing: 84685 tests, 72 workers --
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90.
FAIL: lit :: shtest-recursive-substitution.py (81602 of 84685)
******************** TEST 'lit :: shtest-recursive-substitution.py' FAILED ********************
Exit Code: 2

Command Output (stdout):
--
# RUN: at line 4
env -u FILECHECK_OPTS "/usr/bin/python3" /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit.py -j1 --order=lexical Inputs/shtest-recursive-substitution/substitutes-within-limit --show-all | FileCheck --check-prefix=CHECK-TEST1 /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build2_asan/utils/lit/tests/shtest-recursive-substitution.py
# executed command: env -u FILECHECK_OPTS /usr/bin/python3 /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit.py -j1 --order=lexical Inputs/shtest-recursive-substitution/substitutes-within-limit --show-all
# note: command had no output on stdout or stderr
# executed command: FileCheck --check-prefix=CHECK-TEST1 /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build2_asan/utils/lit/tests/shtest-recursive-substitution.py
# note: command had no output on stdout or stderr
# RUN: at line 8
not env -u FILECHECK_OPTS "/usr/bin/python3" /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit.py -j1 --order=lexical Inputs/shtest-recursive-substitution/does-not-substitute-within-limit --show-all | FileCheck --check-prefix=CHECK-TEST2 /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build2_asan/utils/lit/tests/shtest-recursive-substitution.py
# executed command: not env -u FILECHECK_OPTS /usr/bin/python3 /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit.py -j1 --order=lexical Inputs/shtest-recursive-substitution/does-not-substitute-within-limit --show-all
# note: command had no output on stdout or stderr
# executed command: FileCheck --check-prefix=CHECK-TEST2 /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build2_asan/utils/lit/tests/shtest-recursive-substitution.py
# note: command had no output on stdout or stderr
# RUN: at line 12
env -u FILECHECK_OPTS "/usr/bin/python3" /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit.py -j1 --order=lexical Inputs/shtest-recursive-substitution/does-not-substitute-no-limit --show-all | FileCheck --check-prefix=CHECK-TEST3 /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build2_asan/utils/lit/tests/shtest-recursive-substitution.py
# executed command: env -u FILECHECK_OPTS /usr/bin/python3 /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit.py -j1 --order=lexical Inputs/shtest-recursive-substitution/does-not-substitute-no-limit --show-all
# note: command had no output on stdout or stderr
# executed command: FileCheck --check-prefix=CHECK-TEST3 /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build2_asan/utils/lit/tests/shtest-recursive-substitution.py
# note: command had no output on stdout or stderr
# RUN: at line 16
not env -u FILECHECK_OPTS "/usr/bin/python3" /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit.py -j1 --order=lexical Inputs/shtest-recursive-substitution/not-an-integer --show-all 2>&1 | FileCheck --check-prefix=CHECK-TEST4 /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build2_asan/utils/lit/tests/shtest-recursive-substitution.py
# executed command: not env -u FILECHECK_OPTS /usr/bin/python3 /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit.py -j1 --order=lexical Inputs/shtest-recursive-substitution/not-an-integer --show-all
# note: command had no output on stdout or stderr
# executed command: FileCheck --check-prefix=CHECK-TEST4 /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build2_asan/utils/lit/tests/shtest-recursive-substitution.py
# .---command stderr------------
# | FileCheck error: '<stdin>' is empty.
# | FileCheck command line:  FileCheck --check-prefix=CHECK-TEST4 /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build2_asan/utils/lit/tests/shtest-recursive-substitution.py
# `-----------------------------
# error: command failed with exit status: 2

--

********************
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90.. 
Step 14 (stage3/asan check) failure: stage3/asan check (failure)
...
llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520: note: using lld-link: /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build2_asan/bin/lld-link
llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520: note: using ld64.lld: /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build2_asan/bin/ld64.lld
llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520: note: using wasm-ld: /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build2_asan/bin/wasm-ld
llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520: note: using ld.lld: /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build2_asan/bin/ld.lld
llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520: note: using lld-link: /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build2_asan/bin/lld-link
llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520: note: using ld64.lld: /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build2_asan/bin/ld64.lld
llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:520: note: using wasm-ld: /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build2_asan/bin/wasm-ld
llvm-lit: /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/main.py:73: note: The test suite configuration requested an individual test timeout of 0 seconds but a timeout of 900 seconds was requested on the command line. Forcing timeout to be 900 seconds.
-- Testing: 84685 tests, 72 workers --
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90.
FAIL: lit :: shtest-recursive-substitution.py (81602 of 84685)
******************** TEST 'lit :: shtest-recursive-substitution.py' FAILED ********************
Exit Code: 2

Command Output (stdout):
--
# RUN: at line 4
env -u FILECHECK_OPTS "/usr/bin/python3" /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit.py -j1 --order=lexical Inputs/shtest-recursive-substitution/substitutes-within-limit --show-all | FileCheck --check-prefix=CHECK-TEST1 /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build2_asan/utils/lit/tests/shtest-recursive-substitution.py
# executed command: env -u FILECHECK_OPTS /usr/bin/python3 /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit.py -j1 --order=lexical Inputs/shtest-recursive-substitution/substitutes-within-limit --show-all
# note: command had no output on stdout or stderr
# executed command: FileCheck --check-prefix=CHECK-TEST1 /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build2_asan/utils/lit/tests/shtest-recursive-substitution.py
# note: command had no output on stdout or stderr
# RUN: at line 8
not env -u FILECHECK_OPTS "/usr/bin/python3" /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit.py -j1 --order=lexical Inputs/shtest-recursive-substitution/does-not-substitute-within-limit --show-all | FileCheck --check-prefix=CHECK-TEST2 /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build2_asan/utils/lit/tests/shtest-recursive-substitution.py
# executed command: not env -u FILECHECK_OPTS /usr/bin/python3 /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit.py -j1 --order=lexical Inputs/shtest-recursive-substitution/does-not-substitute-within-limit --show-all
# note: command had no output on stdout or stderr
# executed command: FileCheck --check-prefix=CHECK-TEST2 /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build2_asan/utils/lit/tests/shtest-recursive-substitution.py
# note: command had no output on stdout or stderr
# RUN: at line 12
env -u FILECHECK_OPTS "/usr/bin/python3" /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit.py -j1 --order=lexical Inputs/shtest-recursive-substitution/does-not-substitute-no-limit --show-all | FileCheck --check-prefix=CHECK-TEST3 /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build2_asan/utils/lit/tests/shtest-recursive-substitution.py
# executed command: env -u FILECHECK_OPTS /usr/bin/python3 /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit.py -j1 --order=lexical Inputs/shtest-recursive-substitution/does-not-substitute-no-limit --show-all
# note: command had no output on stdout or stderr
# executed command: FileCheck --check-prefix=CHECK-TEST3 /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build2_asan/utils/lit/tests/shtest-recursive-substitution.py
# note: command had no output on stdout or stderr
# RUN: at line 16
not env -u FILECHECK_OPTS "/usr/bin/python3" /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit.py -j1 --order=lexical Inputs/shtest-recursive-substitution/not-an-integer --show-all 2>&1 | FileCheck --check-prefix=CHECK-TEST4 /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build2_asan/utils/lit/tests/shtest-recursive-substitution.py
# executed command: not env -u FILECHECK_OPTS /usr/bin/python3 /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit.py -j1 --order=lexical Inputs/shtest-recursive-substitution/not-an-integer --show-all
# note: command had no output on stdout or stderr
# executed command: FileCheck --check-prefix=CHECK-TEST4 /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build2_asan/utils/lit/tests/shtest-recursive-substitution.py
# .---command stderr------------
# | FileCheck error: '<stdin>' is empty.
# | FileCheck command line:  FileCheck --check-prefix=CHECK-TEST4 /home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build2_asan/utils/lit/tests/shtest-recursive-substitution.py
# `-----------------------------
# error: command failed with exit status: 2

--

********************
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90.. 

rorth pushed a commit to rorth/llvm-project that referenced this pull request Jun 11, 2025
DhruvSrivastavaX pushed a commit to DhruvSrivastavaX/lldb-for-aix that referenced this pull request Jun 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[SimplifyCFG] Assertion `getArgOperand(ArgNo)->getType()->isPointerTy() && "Argument must be a pointer"' failed.
4 participants