[llvm] r273762 - The absence of noreturn doesn't ensure mayReturn

David Majnemer via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 24 17:55:12 PDT 2016


Author: majnemer
Date: Fri Jun 24 19:55:12 2016
New Revision: 273762

URL: http://llvm.org/viewvc/llvm-project?rev=273762&view=rev
Log:
The absence of noreturn doesn't ensure mayReturn

There are two separate issues:
- LLVM doesn't consider infinite loops to be side effects: we happily
  hoist/sink above/below loops whose bounds are unknown.
- The absence of the noreturn attribute is insufficient for us to know
  if a function will definitely return.  Relying on noreturn in the
  middle-end for any property is an accident waiting to happen.

Removed:
    llvm/trunk/test/Transforms/FunctionAttrs/noreturn.ll
Modified:
    llvm/trunk/include/llvm/IR/Instruction.h
    llvm/trunk/lib/IR/Instruction.cpp

Modified: llvm/trunk/include/llvm/IR/Instruction.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Instruction.h?rev=273762&r1=273761&r2=273762&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/Instruction.h (original)
+++ llvm/trunk/include/llvm/IR/Instruction.h Fri Jun 24 19:55:12 2016
@@ -394,21 +394,13 @@ public:
   /// Return true if this instruction may throw an exception.
   bool mayThrow() const;
 
-  /// Return true if this is a function that may return.
-  /// This is true for all normal instructions. The only exception
-  /// is functions that are marked with the 'noreturn' attribute.
-  ///
-  bool mayReturn() const;
-
   /// Return true if the instruction may have side effects.
   ///
   /// Note that this does not consider malloc and alloca to have side
   /// effects because the newly allocated memory is completely invisible to
   /// instructions which don't use the returned value.  For cases where this
   /// matters, isSafeToSpeculativelyExecute may be more appropriate.
-  bool mayHaveSideEffects() const {
-    return mayWriteToMemory() || mayThrow() || !mayReturn();
-  }
+  bool mayHaveSideEffects() const { return mayWriteToMemory() || mayThrow(); }
 
   /// Return true if the instruction is a variety of EH-block.
   bool isEHPad() const {

Modified: llvm/trunk/lib/IR/Instruction.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Instruction.cpp?rev=273762&r1=273761&r2=273762&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Instruction.cpp (original)
+++ llvm/trunk/lib/IR/Instruction.cpp Fri Jun 24 19:55:12 2016
@@ -545,12 +545,6 @@ bool Instruction::mayThrow() const {
   return isa<ResumeInst>(this);
 }
 
-bool Instruction::mayReturn() const {
-  if (const CallInst *CI = dyn_cast<CallInst>(this))
-    return !CI->doesNotReturn();
-  return true;
-}
-
 /// isAssociative - Return true if the instruction is associative:
 ///
 ///   Associative operators satisfy:  x op (y op z) === (x op y) op z

Removed: llvm/trunk/test/Transforms/FunctionAttrs/noreturn.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/FunctionAttrs/noreturn.ll?rev=273761&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/FunctionAttrs/noreturn.ll (original)
+++ llvm/trunk/test/Transforms/FunctionAttrs/noreturn.ll (removed)
@@ -1,18 +0,0 @@
-; RUN: opt < %s -functionattrs -instcombine -S | FileCheck %s
-
-define void @endless_loop() noreturn nounwind readnone ssp uwtable {
-entry:
-  br label %while.body
-
-while.body:
-  br label %while.body
-}
-;CHECK-LABEL: @main(
-;CHECK: endless_loop
-;CHECK: ret
-define i32 @main() noreturn nounwind ssp uwtable {
-entry:
-  tail call void @endless_loop()
-  unreachable
-}
-




More information about the llvm-commits mailing list