[llvm] r279973 - [Constant] remove fdiv and frem from canTrap()

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 29 08:27:18 PDT 2016


Author: spatel
Date: Mon Aug 29 10:27:17 2016
New Revision: 279973

URL: http://llvm.org/viewvc/llvm-project?rev=279973&view=rev
Log:
[Constant] remove fdiv and frem from canTrap()

Assuming the default FP env, we should not treat fdiv and frem any differently in terms of
trapping behavior than any other FP op. Ie, FP ops do not trap with the default FP env.

This matches how we treat the fdiv/frem in IR with isSafeToSpeculativelyExecute() and in 
the backend after:
https://reviews.llvm.org/rL279970


Modified:
    llvm/trunk/lib/IR/Constants.cpp
    llvm/trunk/test/Transforms/SimplifyCFG/ConditionalTrappingConstantExpr.ll

Modified: llvm/trunk/lib/IR/Constants.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Constants.cpp?rev=279973&r1=279972&r2=279973&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Constants.cpp (original)
+++ llvm/trunk/lib/IR/Constants.cpp Mon Aug 29 10:27:17 2016
@@ -347,10 +347,8 @@ static bool canTrapImpl(const Constant *
     return false;
   case Instruction::UDiv:
   case Instruction::SDiv:
-  case Instruction::FDiv:
   case Instruction::URem:
   case Instruction::SRem:
-  case Instruction::FRem:
     // Div and rem can trap if the RHS is not known to be non-zero.
     if (!isa<ConstantInt>(CE->getOperand(1)) ||CE->getOperand(1)->isNullValue())
       return true;

Modified: llvm/trunk/test/Transforms/SimplifyCFG/ConditionalTrappingConstantExpr.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SimplifyCFG/ConditionalTrappingConstantExpr.ll?rev=279973&r1=279972&r2=279973&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/SimplifyCFG/ConditionalTrappingConstantExpr.ll (original)
+++ llvm/trunk/test/Transforms/SimplifyCFG/ConditionalTrappingConstantExpr.ll Mon Aug 29 10:27:17 2016
@@ -48,16 +48,13 @@ bb7:
   ret i32 927
 }
 
-; FIXME: FP ops don't trap by default, so this is safe to hoist.
+; FP ops don't trap by default, so this is safe to hoist.
 
 define i32 @tarp(i1 %c) {
 ; CHECK-LABEL: @tarp(
-; CHECK-NEXT:    br i1 %c, label %bb8, label %bb9
-; CHECK:       bb8:
+; CHECK-NEXT:  bb9:
 ; CHECK-NEXT:    [[DOT:%.*]] = select i1 fcmp oeq (float fdiv (float 3.000000e+00, float sitofp (i32 ptrtoint (i32* @G to i32) to float)), float 1.000000e+00), i32 42, i32 927
-; CHECK-NEXT:    br label %bb9
-; CHECK:       bb9:
-; CHECK-NEXT:    [[MERGE:%.*]] = phi i32 [ 42, %0 ], [ [[DOT]], %bb8 ]
+; CHECK-NEXT:    [[MERGE:%.*]] = select i1 %c, i32 [[DOT]], i32 42
 ; CHECK-NEXT:    ret i32 [[MERGE]]
 ;
   br i1 %c, label %bb8, label %bb9




More information about the llvm-commits mailing list