Index: llvm/include/llvm/CodeGen/SelectionDAGNodes.h =================================================================== --- llvm/include/llvm/CodeGen/SelectionDAGNodes.h +++ llvm/include/llvm/CodeGen/SelectionDAGNodes.h @@ -359,7 +359,8 @@ private: // This bit is used to determine if the flags are in a defined state. // Flag bits can only be masked out during intersection if the masking flags - // are defined. + // are defined, but in that case the NoUnsignedWrap/NoSignedWrap flags are + // cleared. bool AnyDefined : 1; bool NoUnsignedWrap : 1; @@ -464,13 +465,13 @@ bool hasAllowReassociation() const { return AllowReassociation; } bool hasNoFPExcept() const { return NoFPExcept; } - /// Clear any flags in this flag set that aren't also set in Flags. - /// If the given Flags are undefined then don't do anything. + /// Clear any flags in this flag set that aren't also set in Flags. If the + /// given Flags are undefined then don't do anything with the FP flags. void intersectWith(const SDNodeFlags Flags) { - if (!Flags.isDefined()) - return; NoUnsignedWrap &= Flags.NoUnsignedWrap; NoSignedWrap &= Flags.NoSignedWrap; + if (!Flags.isDefined()) + return; Exact &= Flags.Exact; NoNaNs &= Flags.NoNaNs; NoInfs &= Flags.NoInfs; Index: llvm/test/CodeGen/SystemZ/int-cmp-60.ll =================================================================== --- /dev/null +++ llvm/test/CodeGen/SystemZ/int-cmp-60.ll @@ -0,0 +1,25 @@ +; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z14 -print-after-isel 2>&1 | FileCheck %s +; REQUIRES: asserts +; +; Test that DAGCombiner properly clears the NUW/NSW flags on the memoized add +; node. + +; CHECK: # After Instruction Selection: +; CHECK-LABEL: bb.0.entry: +; CHECK: = AFIMux +; CHECK-NOT: = nuw nsw AFIMux + +define void @fun(i64* %Src, i32* %Dst) { +entry: + %0 = load i64, i64* %Src, align 8 + %1 = trunc i64 %0 to i32 + %conv = and i32 %1, 1303940520 + %xor11.i = or i32 %conv, -2147483648 + %xor2.i = add i32 %xor11.i, -519348290 + %cmp.i = icmp slt i32 %xor2.i, 0 + %sub3.i = add nuw nsw i32 %conv, 1628135358 + %cond.i = select i1 %cmp.i, i32 %conv, i32 %sub3.i + store i32 %cond.i, i32* %Dst + ret void +} +