[llvm] 0640845 - Revert "[SCCP] Use SimplifyBinOp for non-integer constant/expressions & overdef."

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 14 03:57:40 PDT 2020


Thanks for the test case. I’ve recommitted together with a fix in 38609fa9e42aef24b64055817ed01cd015648608, including a slightly more reduced version of the original test case.

> On Apr 13, 2020, at 10:27, Benjamin Kramer via llvm-commits <llvm-commits at lists.llvm.org> wrote:
> 
> 
> Author: Benjamin Kramer
> Date: 2020-04-13T11:23:26+02:00
> New Revision: 06408451bf12d4baed1fb1312d8af6e6bbb6a797
> 
> URL: https://github.com/llvm/llvm-project/commit/06408451bf12d4baed1fb1312d8af6e6bbb6a797
> DIFF: https://github.com/llvm/llvm-project/commit/06408451bf12d4baed1fb1312d8af6e6bbb6a797.diff
> 
> LOG: Revert "[SCCP] Use SimplifyBinOp for non-integer constant/expressions & overdef."
> 
> This reverts commit 1a02aaeaa4f8675490da38ee8cb0d4a6d39815dd. Crashes on
> the following test case:
> 
> $ cat crash.ll
> source_filename = "__compute_module"
> target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
> target triple = "x86_64-grtev4-linux-gnu"
> 
> @0 = private unnamed_addr constant [24 x i8] c"\00\00\C0\7F\00\00\C0\7F\09\85\08?\ED\C94\FE~\EB/\F3\90\CF\BA\C1"
> @1 = private unnamed_addr constant [24 x i8] c"\00\00\C0\7F\A3\A0\0FA\00\00\C0\7F\00\00\C0\7F\00\00\00\00\02\9AA\00"
> 
> define void @IgammaSpecialValues.448() {
> entry:
>  br label %fusion.26.loop_header.dim.0
> 
> fusion.26.loop_header.dim.0:                      ; preds = %fusion.26.loop_header.dim.0, %entry
>  %fusion.26.invar_address.dim.0.0 = phi i64 [ 0, %entry ], [ %invar.inc17, %fusion.26.loop_header.dim.0 ]
>  %0 = getelementptr inbounds [6 x float], [6 x float]* bitcast ([24 x i8]* @0 to [6 x float]*), i64 0, i64 %fusion.26.invar_address.dim.0.0
>  %1 = load float, float* %0
>  %2 = fmul float %1, 0.000000e+00
>  %3 = getelementptr inbounds [6 x float], [6 x float]* bitcast ([24 x i8]* @1 to [6 x float]*), i64 0, i64 %fusion.26.invar_address.dim.0.0
>  %4 = load float, float* %3
>  %5 = fneg float %4
>  %6 = fadd float %2, %5
>  %invar.inc17 = add nuw nsw i64 %fusion.26.invar_address.dim.0.0, 1
>  br label %fusion.26.loop_header.dim.0
> }
> 
> $ opt -ipsccp -S < crash.ll
> opt: llvm/include/llvm/Analysis/ValueLattice.h:251: bool llvm::ValueLatticeElement::markConstant(llvm::Constant *, bool): Assertion `getConstant() == V && "Marking constant with different value"' failed.
> 
> Added: 
> 
> 
> Modified: 
>    llvm/lib/Transforms/Scalar/SCCP.cpp
>    llvm/test/Transforms/SCCP/ub-shift.ll
>    llvm/test/Transforms/SCCP/vector-bitcast.ll
> 
> Removed: 
> 
> 
> 
> ################################################################################
> diff  --git a/llvm/lib/Transforms/Scalar/SCCP.cpp b/llvm/lib/Transforms/Scalar/SCCP.cpp
> index 2953c30fe49a..c8d7c4de37fc 100644
> --- a/llvm/lib/Transforms/Scalar/SCCP.cpp
> +++ b/llvm/lib/Transforms/Scalar/SCCP.cpp
> @@ -28,7 +28,6 @@
> #include "llvm/ADT/Statistic.h"
> #include "llvm/Analysis/ConstantFolding.h"
> #include "llvm/Analysis/GlobalsModRef.h"
> -#include "llvm/Analysis/InstructionSimplify.h"
> #include "llvm/Analysis/TargetLibraryInfo.h"
> #include "llvm/Analysis/ValueLattice.h"
> #include "llvm/Analysis/ValueLatticeUtils.h"
> @@ -370,10 +369,8 @@ class SCCPSolver : public InstVisitor<SCCPSolver> {
>   // markConstant - Make a value be marked as "constant".  If the value
>   // is not already a constant, add it to the instruction work list so that
>   // the users of the instruction are updated later.
> -  bool markConstant(ValueLatticeElement &IV, Value *V, Constant *C,
> -                    bool MayIncludeUndef = false) {
> -    if (!IV.markConstant(C, MayIncludeUndef))
> -      return false;
> +  bool markConstant(ValueLatticeElement &IV, Value *V, Constant *C) {
> +    if (!IV.markConstant(C)) return false;
>     LLVM_DEBUG(dbgs() << "markConstant: " << *C << ": " << *V << '\n');
>     pushToWorkList(IV, V);
>     return true;
> @@ -957,28 +954,23 @@ void SCCPSolver::visitBinaryOperator(Instruction &I) {
>   if (V1State.isOverdefined() && V2State.isOverdefined())
>     return (void)markOverdefined(&I);
> 
> -  // If either of the operands is a constant, try to fold it to a constant.
> +  // Both operands are non-integer constants or constant expressions.
>   // TODO: Use information from notconstant better.
> -  if ((V1State.isConstant() || V2State.isConstant())) {
> -    Value *V1 = isConstant(V1State) ? getConstant(V1State) : I.getOperand(0);
> -    Value *V2 = isConstant(V2State) ? getConstant(V2State) : I.getOperand(1);
> -    Value *R = SimplifyBinOp(I.getOpcode(), V1, V2, SimplifyQuery(DL));
> -    auto *C = dyn_cast_or_null<Constant>(R);
> -    if (C) {
> -      // X op Y -> undef.
> -      if (isa<UndefValue>(C))
> -        return;
> -      // Conservatively assume that the result may be based on operands that may
> -      // be undef.
> -      return (void)markConstant(IV, &I, C, /*MayIncludeUndef=*/true);
> -    }
> +  if (isConstant(V1State) && isConstant(V2State)) {
> +    Constant *C = ConstantExpr::get(I.getOpcode(), getConstant(V1State),
> +                                    getConstant(V2State));
> +    // X op Y -> undef.
> +    if (isa<UndefValue>(C))
> +      return;
> +    return (void)markConstant(IV, &I, C);
>   }
> 
>   // Only use ranges for binary operators on integers.
>   if (!I.getType()->isIntegerTy())
>     return markOverdefined(&I);
> 
> -  // Try to simplify to a constant range.
> +  // Operands are either constant ranges, notconstant, overdefined or one of the
> +  // operands is a constant.
>   ConstantRange A = ConstantRange::getFull(I.getType()->getScalarSizeInBits());
>   ConstantRange B = ConstantRange::getFull(I.getType()->getScalarSizeInBits());
>   if (V1State.isConstantRange())
> 
> diff  --git a/llvm/test/Transforms/SCCP/ub-shift.ll b/llvm/test/Transforms/SCCP/ub-shift.ll
> index fbcaef422870..6e15d6b2bccd 100644
> --- a/llvm/test/Transforms/SCCP/ub-shift.ll
> +++ b/llvm/test/Transforms/SCCP/ub-shift.ll
> @@ -3,8 +3,10 @@
> 
> define void @shift_undef_64(i64* %p) {
> ; CHECK-LABEL: @shift_undef_64(
> -; CHECK-NEXT:    store i64 0, i64* [[P:%.*]]
> -; CHECK-NEXT:    store i64 -1, i64* [[P]]
> +; CHECK-NEXT:    [[R1:%.*]] = lshr i64 -1, 4294967296
> +; CHECK-NEXT:    store i64 [[R1]], i64* [[P:%.*]]
> +; CHECK-NEXT:    [[R2:%.*]] = ashr i64 -1, 4294967297
> +; CHECK-NEXT:    store i64 [[R2]], i64* [[P]]
> ; CHECK-NEXT:    [[R3:%.*]] = shl i64 -1, 4294967298
> ; CHECK-NEXT:    store i64 [[R3]], i64* [[P]]
> ; CHECK-NEXT:    ret void
> @@ -23,8 +25,10 @@ define void @shift_undef_64(i64* %p) {
> 
> define void @shift_undef_65(i65* %p) {
> ; CHECK-LABEL: @shift_undef_65(
> -; CHECK-NEXT:    store i65 0, i65* [[P:%.*]]
> -; CHECK-NEXT:    store i65 0, i65* [[P]]
> +; CHECK-NEXT:    [[R1:%.*]] = lshr i65 2, -18446744073709551615
> +; CHECK-NEXT:    store i65 [[R1]], i65* [[P:%.*]]
> +; CHECK-NEXT:    [[R2:%.*]] = ashr i65 4, -18446744073709551615
> +; CHECK-NEXT:    store i65 [[R2]], i65* [[P]]
> ; CHECK-NEXT:    [[R3:%.*]] = shl i65 1, -18446744073709551615
> ; CHECK-NEXT:    store i65 [[R3]], i65* [[P]]
> ; CHECK-NEXT:    ret void
> @@ -43,8 +47,10 @@ define void @shift_undef_65(i65* %p) {
> 
> define void @shift_undef_256(i256* %p) {
> ; CHECK-LABEL: @shift_undef_256(
> -; CHECK-NEXT:    store i256 0, i256* [[P:%.*]]
> -; CHECK-NEXT:    store i256 0, i256* [[P]]
> +; CHECK-NEXT:    [[R1:%.*]] = lshr i256 2, 18446744073709551617
> +; CHECK-NEXT:    store i256 [[R1]], i256* [[P:%.*]]
> +; CHECK-NEXT:    [[R2:%.*]] = ashr i256 4, 18446744073709551618
> +; CHECK-NEXT:    store i256 [[R2]], i256* [[P]]
> ; CHECK-NEXT:    [[R3:%.*]] = shl i256 1, 18446744073709551619
> ; CHECK-NEXT:    store i256 [[R3]], i256* [[P]]
> ; CHECK-NEXT:    ret void
> @@ -63,8 +69,10 @@ define void @shift_undef_256(i256* %p) {
> 
> define void @shift_undef_511(i511* %p) {
> ; CHECK-LABEL: @shift_undef_511(
> -; CHECK-NEXT:    store i511 0, i511* [[P:%.*]]
> -; CHECK-NEXT:    store i511 -1, i511* [[P]]
> +; CHECK-NEXT:    [[R1:%.*]] = lshr i511 -1, 1208925819614629174706276
> +; CHECK-NEXT:    store i511 [[R1]], i511* [[P:%.*]]
> +; CHECK-NEXT:    [[R2:%.*]] = ashr i511 -2, 1208925819614629174706200
> +; CHECK-NEXT:    store i511 [[R2]], i511* [[P]]
> ; CHECK-NEXT:    [[R3:%.*]] = shl i511 -3, 1208925819614629174706180
> ; CHECK-NEXT:    store i511 [[R3]], i511* [[P]]
> ; CHECK-NEXT:    ret void
> 
> diff  --git a/llvm/test/Transforms/SCCP/vector-bitcast.ll b/llvm/test/Transforms/SCCP/vector-bitcast.ll
> index b032085083c6..35312034c65b 100644
> --- a/llvm/test/Transforms/SCCP/vector-bitcast.ll
> +++ b/llvm/test/Transforms/SCCP/vector-bitcast.ll
> @@ -2,7 +2,8 @@
> 
> target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128-n8:16:32-S128"
> 
> -; CHECK: store volatile <2 x i64> zeroinitializer, <2 x i64>* %p
> +; FIXME: Add back support for handling special values of vector/fp types.
> +; CHECK: store volatile <2 x i64> %and.i119.i, <2 x i64>* %p
> ; rdar://11324230
> 
> define void @foo(<2 x i64>* %p) nounwind {
> 
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits



More information about the llvm-commits mailing list